gradle test运行我的测试类,但不是自定义测试任务

时间:2015-02-22 12:32:01

标签: java testing junit build gradle

这是我的测试类:

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"只运行此测试类,我应该修复什么?

1 个答案:

答案 0 :(得分:2)

您可以使用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