2017-10-06 28 views
0

我有一些測試(TestNG的註釋):潤集團TestNG的測試中gradle這個

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

@Test(groups={"Example"}) 
public void Test2(){...} 

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

而且在文件的build.gradle我可以運行組測試下一方式:

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

但我想通過gradle命令行來運行這個「Example」組作爲參數,就像我們用單個測試gradle -Dtest.single=... test一樣。 Gradle有沒有可能做類似gradle -Dtest.groups=Example test的事情?

回答

1

其實你不應該使用gradlew -Dtest.single=... test,而是gradlew test --tests ...

您可以通過評估項目屬性(如includeGroups(project.findProperty('testGroups') ?: 'DefaultGroup')),然後您可以執行gradlew test -P testGroups=Example來輕鬆配置自己的這種可能性。

+0

當我設置includeGroups(testGroups?:'DefaultGroup')時,我得到一個錯誤: '''無法獲取類型爲org.gradle.api.tasks.testing.testng.TestNGOptions的對象的未知屬性'testGroups'。 ''' – Konstantin