[英]In ScalaTest, how can I specify test tags via a system property
我正在将新的Scala代码与现有系统集成在一起。 当前,通过设置系统属性“ integration”来触发我们的数据库测试(通过Maven和现有的IDE配置)。 这使我们可以这样做,例如:
mvn test -Dintegration
包括数据库测试。 如果我们放弃该属性,那么将跳过测试。 基本上,我们现有的JUnit测试具有以下功能(这样做比较干净,但是您会明白这一点):
assumeTrue(System.getProperty("integration") != null)
当我添加新的Scala代码时(注意:再次使用JUnitRunner,所以一切都可以使用),并且我需要能够做等效的事情。...而且我不想重建我的整个基础结构(持续集成) ,等等)...我想做的是编写一个基本特征或类似内容,以便将系统属性转换为可以跳过(或包含)测试的内容。
有任何想法吗?
我阅读了源代码,看起来JUnitRunner甚至不支持以当前形式提供标签。 但是,代码非常简单,因此事实证明,最好的方法是从现有运行器中复制代码,并对其进行修改以满足我的需求。
以下是由于软件包许可等原因引起的要求。
除此之外,您可以简单地复制现有的JUnitRunner并将run()方法修改为:
def run(notifier: RunNotifier) {
val ignoreTags = Set("org.scalatest.Ignore") // the built in ignore support
val integrationTags = Set(DbTest.name)
val (tagsToRun, tagsToSkip) =
(if (System.getProperty("integration") == null)
(None, integrationTags ++ ignoreTags)
else
(Some(integrationTags), ignoreTags)
)
try {
suiteToRun.run(None, Args(new RunNotifierReporter(notifier),
Stopper.default, Filter(tagsToRun, tagsToSkip), Map(), None,
new Tracker, Set.empty))
}
catch {
case e: Exception =>
notifier.fireTestFailure(new Failure(getDescription, e))
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.