Gradle command syntax for executing TESTNG tests a

2019-07-24 00:56发布

问题:

I have some tests as below:

@Test(groups={"smoke"})
public void Test1(){...}

@Test(groups={"smoke", "regression"})
public void Test2(){...}

@Test(groups={"regression"})
public void Test3(){...}

In build.gradle file I have below:

task smoketests(type: Test){
useTestNG() {
   suites "src/test/resources/testng.xml"
   includeGroups "smoke"
}

}

I need to have a gradle syntax to run the smoke/regression tests only using commandline. I have tried this:

./gradlew clean test -P testGroups="smoke"

if I run that, build is successful as below:

:clean
:compileJava
:processResources UP-TO-DATE
:classes
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test
BUILD SUCCESSFUL
Total time: 42.253 secs

But it never execute actual tests. Need help

回答1:

You have created a custom test task, so you need to use that instead of test in your command line:

gradlew clean smoketests