Gradle + TestNG Only Running Specified Group

2019-06-10 09:37发布

问题:

Trying to reorganize a very large library of tests by grouping them into different areas. What I've done so far is create a "api-crud" group within TestNG and setting the @Test parameters accordingly.

How can I, in gradle, run only these tests? When I try to do the following:

includeGroups 'api-crud'

gradle seems to run everything still.

I've seen some of the examples of setting excludeGroups, but that is currently unrealistic due to the size and scope of the project.

回答1:

includeGroups worked for me. Try running gradle clean test -i. Here is what I tested with:

src/main/java/Greeter.java:

public class Greeter {..}

src/test/java/GreeterTest.java:

public class GreeterTest {

    private Greeter greeter = new Greeter();

    @Test(groups = ("simple"))
    public void sayHi_default() {..}

    @Test(groups = ("personalized"))
    public void sayHi_with_args() {..}
}

build.gradle:

apply plugin: 'java'

sourceCompatibility = 1.7
version = '1.0'

repositories {
    mavenCentral()
}

dependencies {
    testCompile 'org.testng:testng:6.8.21'
}

test {
    useTestNG() {
        includeGroups 'simple'
    }
}