簡體   English   中英

gradle test運行我的測試類,但不運行自定義測試任務

[英]gradle test runs my test class, but not a custom test task

這是我的測試課:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM