这是我的测试类:
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"
只运行这个测试类,我应该修复什么?
最佳答案
您可以使用 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
关于java - gradle test 运行我的测试类,但不是自定义测试任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28657833/