junit 如何在Gradle中使用命令行按多个类别运行测试?

7gs2gvoe  于 2022-11-11  发布在  其他
关注(0)|答案(2)|浏览(123)

我有几个测试,每个测试都标记有下面列出的一个或多个类别

@Category(SmokeTest.class)
@Category(RegressionTest.class)
@Category(StressTest.class)

我如何运行多个类别的测试?例如,我必须在命令行中写什么来运行类别为“SmokeTest”和“StressTest”的测试?
在build.gradle中,我必须补充一点:

test {
    useJUnit() {
        if (project.hasProperty("cat"))
            includeCategories "com.path.to.categories.interfaces.folder.$cat"
    }
}

然后在终端中输入以下命令:

./gradle clean test -Pcat=SmokeTest,StressTest

但它不起作用。

mv1qrgav

mv1qrgav1#

我猜你能

def cats = project.property('cat').split(',').collect {
   "com.path.to.categories.interfaces.folder.$it"
} 
includeCategories cats
cyej8jka

cyej8jka2#

you could add this to your gradle file:
test {
    useJUnit {
        if (project.hasProperty("cat"))
            includeCategories = (project.property('cat').split(',').collect 
             {
                "com.philips.dtc.category.$it".toString()
             }) as List
    }
}

命令:Gradle清洁测试-Pcat=烟雾测试,应力测试

相关问题