I'm trying to use gradle to run tests with the following command but its not working
gradle cleanTest test --tests my.package.TestSuite
my test suite looks like the following
@RunWith(Suite.class)
@Suite.SuiteClasses({
ATests.class,
BTests.class,
CTests.class
})
public class MySuite {
/* placeholder, use this to contain all integration tests in one spot * */
}
trying to run the following command works, but aggravatingly enough, it runs each test twice. once by itself and then again under the test suite in that same namespace
gradle clean test --tests my.package.*
I could just drop the test suite and do it this way but I want to better understand whats going on here and why I can't tell it to directly run the test suite.
Use the command ./gradlew test to run all tests.
To run a Gradle command, open a command window on the project folder and enter the Gradle command. Gradle commands look like this: On Windows: gradlew <task1> <task2> … e.g. gradlew clean allTests.
single system property can be used to specify a single test. You can do gradle -Dtest. single=ClassUnderTestTest test if you want to test single class or use regexp like gradle -Dtest. single=ClassName*Test test you can find more examples of filtering classes for tests under this link.
You can run the application by executing the run task (type: JavaExec). This will compile the main source set, and launch a new JVM with its classes (along with all runtime dependencies) as the classpath and using the specified main class.
The following works for me locally.
gradle -Dtest.single=MySuite clean test
This actually uses a different approach (test inclusion) versus the more advanced filtering approach used by --test
.
As documented in the referenced link, the example above works by creating a file inclusion pattern of the form **/MySuite*.class
whereas --test
attempts to select tests from the scanned test set. I suspect there are some unforseen interactions between the generic test filtering implemented in Gradle and the specific cases around the JUnit Suite runner.
Having said that, even the Gradle docs warn that the above approach is superseded, and in reality I would probably echo @Opal's comment and define an explicit task to run suites for a given phase of testing. For example the following run with gradle clean testSuite
might run an integration suite.
task testSuite(type: Test) {
include 'MySuite.class'
}
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With