Run single testsuite with Gradle Java

969 views Asked by At

This is my Gradle script:

test{
    include 'com.foo.MainTestSuite'
    testLogging.showStandardStreams = true
}

And this is my com.foo.MainTestSuite

@RunWith(Suite.class)
@Suite.SuiteClasses({
        NetworkTestSuite.class,
        DataBaseTestSuite.class
})
public class MainTestSuite {

    @BeforeClass
    public static void setup(){
        System.out.println("BeforeClass MainTestSuite");
    }

    @AfterClass
    public static void tearDown(){
        System.out.println("AfterClass MainTestSuite");
    }
}

And then I execute Gradle via command line like that:

./gradlew clean test

But no tests are been run. If I remove the include then all of my tests run but more than once since they are linked from testsuite as well.

What is wrong with my Gradle script, why aren't the MainTestSuite is executed?

1

There are 1 answers

0
Kostiantyn On BEST ANSWER

Try changing your test section in build.gradle to the following:

test{
    filter{
        includeTestsMatching 'com.foo.MainTestSuite'
    }
    testLogging.showStandardStreams = true
}

That will result in exactly what you want

Please refer to the Gradle Test Filtering documentation for further details