【问题标题】:gradle test runs my test class, but not a custom test taskgradle test 运行我的测试类,但不是自定义测试任务
【发布时间】:2015-02-22 12:32:00
【问题描述】:

这是我的测试课:

public class RoutingResponseRegressionOneByOne {


    @BeforeClass
    public static void oneTimeSetUp() {
        routingClient = injector.getInstance(IRoutingClient.class);
        System.out.println("in RoutingResponseRegressionOneByOne:: oneTimeSetUp");
    }

我在 build.gradle 中添加了一个任务

task testRegression(type: Test) {
    systemProperties['test.single'] = '\'RoutingResponseRegressionOneByOne\''
    //systemProperty 'test.single', System.getProperty('test.single', '\'RoutingResponseRegressionOneByOne\'')
}

当我从 intellij 运行 "test" 时,这是输出

但是,当我从 intellij "testRegression" 时,这是输出:

我应该解决什么问题才能让"testRegression" 只运行这个测试类?

【问题讨论】:

  • 你提到的输出是什么?

标签: java testing junit build gradle


【解决方案1】:

您可以使用P 将参数传递给您的任务,并使用TestFilter。

在此链接中,您将找到过滤器使用的完整示例。下面我附上了一个自定义 automationTest 任务的代码,该任务从特定文件夹运行测试。

task automationTest(type: Test) {
    //search for an argument called 'single'. if exists, use it as a test filter
    if (project.hasProperty('single')) {
        filter {
            includeTestsMatching "*${project.property('single')}*"
        }
    }
    useTestNG()

    description = "Runs Automation Tests"
    testClassesDir = file("$buildDir/classes/main/automation")
    classpath += sourceSets.main.runtimeClasspath
}

运行为:gradle -Psingle=MyTest automationTest

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 2017-06-16
    • 1970-01-01
    相关资源
    最近更新 更多