Skip to content

Commit

Permalink
Fix pts with testng (#5339)
Browse files Browse the repository at this point in the history
Motivation:

Recently we have enabled PTS which causes an error when trying to run testNg tests.
```
Execution failed for task ':core:testNg'.
> Predictive Test Selection only supports JUnit Platform.
```

It has been pointed out that `TestNg` is supported through `junit-platform`.
ref: https://docs.gradle.com/enterprise/predictive-test-selection/#_frameworks_and_languages

I see no reason we shouldn't just use `junit-platform` overall as our default test framework launcher.

ref: https://gradle.slack.com/archives/C05975D6V7H/p1701969512592219

Note that we are unable to add the testNg globally by default due to the following issue: junit-team/testng-engine#87

Modifications:

- Added a test engine `testng` to testing runtime
- Modified to always use `useJUnitPlatform()`

Result:

- We can run testNg tests with PTS enabled
  • Loading branch information
jrhee17 authored Jan 2, 2024
1 parent 02cbc34 commit ca31809
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ allprojects {
tasks.withType(Test) {
jvmArgumentProviders.add(new TestBuildDirArgumentsProvider(project.buildDir))

useJUnitPlatform()

// Do not omit stack frames for easier tracking.
jvmArgs '-XX:-OmitStackTraceInFastThrow'

Expand Down
4 changes: 3 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ mrJarVersions.each { version->
testClassesDirs = sourceSets."java${version}Test".output.classesDirs
classpath = sourceSets."java${version}Test".runtimeClasspath

useJUnitPlatform()
project.ext.configureCommonTestSettings(it)
enabled = project.ext.testJavaVersion >= targetJavaVersion
}
Expand Down Expand Up @@ -225,6 +224,9 @@ if (rootProject.findProperty('flakyTests') != 'true') {
}
}
}
dependencies {
runtimeOnly libs.junit.testng.engine
}
}
}
tasks.shadedTest.finalizedBy testing.suites.testNg
Expand Down
4 changes: 4 additions & 0 deletions dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,10 @@ module = "org.junit.platform:junit-platform-launcher"
module = "org.junit-pioneer:junit-pioneer"
version.ref = "junit-pioneer"

[libraries.junit-testng-engine]
module = "org.junit.support:testng-engine"
version = "1.0.4"

[libraries.jwt]
module = "com.auth0:java-jwt"
version.ref = "jwt"
Expand Down
4 changes: 4 additions & 0 deletions kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ testing {
}
}
}

dependencies {
runtimeOnly(libs.junit.testng.engine)
}
}
}
}
Expand Down

0 comments on commit ca31809

Please sign in to comment.