我使用以下注释来标记我的集成测试:
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Tag("integration-test")
public @interface IntegrationTest {
}
Run Code Online (Sandbox Code Playgroud)
这是我用来build.gradle从gradle build以下方面排除这些测试的过滤器:
junitPlatform {
filters {
tags {
exclude 'integration-test'
}
}
}
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.
现在我想提供一个专门运行我的集成测试的Gradle任务 - 推荐的方法是什么?
TWi*_*Rob 26
基于https://github.com/gradle/gradle/issues/6172#issuecomment-409883128
test {
useJUnitPlatform {
excludeTags 'integration'
}
}
task integrationTest(type: Test) {
useJUnitPlatform {
includeTags 'integration'
}
check.dependsOn it
shouldRunAfter test
}
Run Code Online (Sandbox Code Playgroud)
gradlew test 将运行测试而不进行集成gradlew integrationTest 将只运行集成测试gradlew check将运行test随后integrationTestgradlew integrationTest test将运行test后跟integrationTestshouldRunAfterplugin: 'org.junit.platform.gradle.plugin'注意:虽然上面的工作,IntelliJ IDEA很难推断出东西,所以我建议使用这个更明确的版本,其中输入所有内容并完全支持代码完成:
tasks.withType(Test) { Test task ->
task.useJUnitPlatform { org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions options ->
options.excludeTags 'integration'
}
}
task integrationTest(type: Test) { Test task ->
task.useJUnitPlatform { org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions options ->
options.includeTags 'integration'
}
tasks.check.dependsOn task
task.shouldRunAfter tasks.test
}
Run Code Online (Sandbox Code Playgroud)
ete*_*ech 13
我不确定是否是因为 Gradle 行为发生了变化,但投票最高的答案在 Gradle 中对我不起作用。6.8.3. 我看到 IntegrationTests 任务与主要测试任务一起运行。这个简化版本对我有用:
test {
useJUnitPlatform {
excludeTags "integration"
}
}
tasks.register("integrationTests", Test) {
useJUnitPlatform {
includeTags "integration"
}
mustRunAfter check
}
Run Code Online (Sandbox Code Playgroud)
命令:
./gradlew test或- 运行没有./gradlew clean build“集成”标签的测试
。./gradlew integrationTests- 仅运行带有“集成”标签的测试
。我提交了一个问题:https://github.com/junit-team/junit5/issues/579(由Sam Brannen建议).
同时,我使用项目属性作为解决方法:
junitPlatform {
filters {
tags {
exclude project.hasProperty('runIntegrationTests') ? '' : 'integration-test'
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,将跳过集成测试:
gradle test
但将包含在:
gradle test -PrunIntegrationTests
| 归档时间: |
|
| 查看次数: |
4623 次 |
| 最近记录: |