我有以下虚拟测试课 package my.test;import org.testng.annotations.*;public class NgScenario { public static void trace(String msg) { System.err.println(msg); } @BeforeClass public void init() { trace("-- NgScenario"); } @AfterClass
package my.test; import org.testng.annotations.*; public class NgScenario { public static void trace(String msg) { System.err.println(msg); } @BeforeClass public void init() { trace("-- NgScenario"); } @AfterClass public void shutdown() { trace("-- NgScenario"); } @Test(dependsOnMethods = {"step2"}) public void step1() throws Exception { trace("-- step1"); } @Test public void step2() throws Exception { trace("-- step2"); } @Test(dependsOnMethods = {"step2"}) public void step3() throws Exception { trace("-- step3"); } }
和build.gradle
apply plugin: 'java' repositories { mavenLocal() mavenCentral() jcenter() } dependencies { compile "org.testng:testng:6.9.10" } test { useTestNG() scanForTestClasses = false include '**/*' beforeTest { descriptor -> logger.lifecycle("Gradle running test: ${descriptor}") } }
当我执行简单的命令gradle测试时 – 一切正常并且输出正在跟随(注意:step2故意依赖于step1来检查订单是否确实正确):
Gradle running test: Test method step2(my.test.NgScenario) Gradle running test: Test method step1(my.test.NgScenario) Gradle running test: Test method step3(my.test.NgScenario)
现在,假设我在方案中有100个方法,并且我想在我的IDE中仅测试单个方法分支 – 我运行命令gradle test –tests my.test.NgScenario.step1并收到此错误
No tests found for given includes: [my.test.NgScenario.step1]
step1在其注释中有dependsOnMethods.没有dependsOnMethods的相同测试命令运行OK:gradle test –tests my.test.NgScenario.step2.
所以问题是 – 我正在做什么/期待错误?
我想要使用测试场景并能够在IDE中启动单独的测试子树.
除此之外 – 能够执行’step1’而没有依赖的任务会很好(假设’父’步骤是’干净设置’ – 调试单个测试时不需要它们,所有先决条件已经在 – 地点).
作为偏离主题 – 可以推荐另一个能够集成到gradle构建中的框架.
试试这个:gradle :clean -Dtest.single=Name_of_your_test_here test