2014-01-15 24 views
0

我正在将新的scala代码与现有系统集成。我们的数据库测试目前是通过设置系统属性“集成”来触发的(通过Maven和现有的IDE配置)。这让我们做到这一点,例如:在ScalaTest中,如何通过系统属性指定测试标记

mvn test -Dintegration 

包括数据库测试。如果我们离开财产,那么测试会被跳过。基本上,我们现有的JUnit测试有(它是清洁了一下这个,但你会得到点):

assumeTrue(System.getProperty("integration") != null) 

正如我添加新的Scala代码(注意:在使用JUnitRunner,再次使这一切只是工作),我需要能够做相当的....我不想重建我的整个基础设施(持续集成等)...我宁愿做的是写一个基本特征或这样我就可以将系统属性转换为允许我跳过(或包含)测试的东西。

任何想法?

回答

1

我读了源代码,它看起来像JUnitRunner甚至不支持以当前形式提供标签;但是,代码很简单,所以最好的方法是从现有的runner复制代码,并修改它以满足我的需求。

以下是由于包权限的要求等

  1. 你不能继承JUnitRunner,因为你需要的比特是私人
  2. 你必须把你的类在同一个包(ORG。 scalatest.junit)

除此之外,你可以简单地复制现有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)) 
    } 
    } 
+0

+1用于阅读信息来源,但是s/it's/its。 –

+0

thx为sed修复 –

相关问题