如何默认禁用所有测试并仅执行符合特定条件的测试
How to disable all tests per default and only execute those that comply with a certain condition
我们 运行 我们的 junit5 在某些环境(开发、预览、生产)上进行测试。在开发和预览中,我想 运行 所有可用的测试,不用多说。在产品上,我只想执行这些测试中的一小部分。
Afaik,可以通过在产品上注释所有不应 运行 的测试来解决此问题,例如:
@EnabledIfSystemProperty(named = "profile", matches = "dev|preview")
annotation class DevAndPreviewOnly
我想知道是否有可能以相反的方式配置它,通过明确指定应在 prod 上执行哪些测试并默认跳过其他测试?
您可以(仅)tag 应该 运行 在产品上进行的测试……
@Tag("prod")
public class MyTests {
// …
}
… 然后使用这样的 Gradle 配置来决定每个构建要 运行 的测试:
test {
useJUnitPlatform {
if (project.hasProperty('prod')) {
includeTags 'prod'
}
// otherwise run all tests
}
}
我们 运行 我们的 junit5 在某些环境(开发、预览、生产)上进行测试。在开发和预览中,我想 运行 所有可用的测试,不用多说。在产品上,我只想执行这些测试中的一小部分。
Afaik,可以通过在产品上注释所有不应 运行 的测试来解决此问题,例如:
@EnabledIfSystemProperty(named = "profile", matches = "dev|preview")
annotation class DevAndPreviewOnly
我想知道是否有可能以相反的方式配置它,通过明确指定应在 prod 上执行哪些测试并默认跳过其他测试?
您可以(仅)tag 应该 运行 在产品上进行的测试……
@Tag("prod")
public class MyTests {
// …
}
… 然后使用这样的 Gradle 配置来决定每个构建要 运行 的测试:
test {
useJUnitPlatform {
if (project.hasProperty('prod')) {
includeTags 'prod'
}
// otherwise run all tests
}
}