我有以下虚拟测试类
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 test
- 一切正常,输出如下(注意: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
。相同的测试命令 without dependsOnMethods
运行正常:gradle test --tests my.test.NgScenario.step2
。
所以问题是 - 我在做什么/预期错了什么?
我既想使用测试场景,又想在 IDE 中启动单独的测试子树。
最重要的是——能够在没有它依赖的任务的情况下执行“step1”会很好(假设“parent”步骤是“clean+setup”——调试单个测试不需要它们必要条件已经到位)。
作为题外话 - 可以推荐另一个能够集成到 gradle 构建中的框架。
最佳答案
试试这个:
gradle :clean -Dtest.single=Name_of_your_test_here test
关于java - "No tests found for given includes"用于 TestNG + Gradle + @Test(dependsOnMethods),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36722818/