微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

对于TestNG Gradle @Test(dependsOnMethods),“没有找到给定包含的测试”

我有以下虚拟测试课

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐