How to run a test package using gradle from the command line

I am trying to use gradle to run tests with the following command, but not working

gradle cleanTest test --tests my.package.TestSuite 

my test suite is as follows

 @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 execute the following command works, but rather evasively, it runs each test twice. once on its own and then again on the test set in the 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 what is happening here and why I can’t tell it to run the test suite directly.

+8
java shell gradle
source share
1 answer

Below works for me locally.

 gradle -Dtest.single=MySuite clean test 

This actually takes a different approach (including the test) compared to the more advanced filtering approach used by --test .

As indicated in the link, the above example works by creating a template to include the form file **/MySuite*.class , while --test tries to select tests from the scanned test suite. I suspect there are some unforeseen interactions between the general test filtering implemented in Gradle and the specific cases around the JUnit Suite runner.

Having said that, even Gradle docs warn that the above approach has been superseded, and in fact I would probably repeat @Opal's comment and define an explicit task to run the suites for this testing phase. For example, the next start with gradle clean testSuite may start the integration package.

 task testSuite(type: Test) { include 'MySuite.class' } 

Literature:

+1
source share

All Articles