Reputation: 91
I tried to run only one test class from Gradle. I used these commands:
gradle -Dtest.single=Junit5Test test
gradle test --tests ru.tests.runner.Junit5Test
But it runs all of the project's tests. I need to run only one test class. Here is my class:
public class Junit5Test {
public static void main(String[] args) {
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(
selectPackage("ru.tests.api")
)
.build();
Launcher launcher = LauncherFactory.create();
launcher.execute(request, new TestExecutionListener());
}
}
It works perfect by right-click run. I use
Upvotes: 4
Views: 2259
Reputation: 1
I resolved it by replacing
gradle -Dtest.single=Junit5Test test
with
gradle -DjunitPlatformTest.single=Junit5Test test
Upvotes: 0
Reputation: 31187
For starters, your Junit5Test
class is not a "test class".
Rather, it is a stand-alone application (i.e., a Java class with a main()
method).
Thus, attempting to execute it as a "test" with Gradle will never work.
If you would like to run JUnit Jupiter tests (or any other tests that run on the JUnit Platform) with Gradle, you should use the JUnit Platform Gradle Plugin (that's a link to the appropriate section of the JUnit 5 User Guide).
Upvotes: 1