2012-10-31 34 views
4

我明白了!我直译了Java在这里为斯卡拉一行一行:Scala中的JUnit测试类别?

https://github.com/junit-team/junit/blob/master/doc/ReleaseNotes4.8.md

主要是它的意思做阵列(classOf [类名]),删除“公”的关键字,等我的IntelliJ IDE帮助了很多与建议。


我希望能够运行的测试类,所以我可能会标记一个类的测试,“Version2dot3”和“SlowTest”,然后能够运行只是“慢测试”,或者运行“慢测试和2.3测试“。

我一直在试图这篇文章,以适应我的斯卡拉测试:

http://weblogs.java.net/blog/johnsmart/archive/2010/04/25/grouping-tests-using-junit-categories-0

我有一个基本的shell设置,几乎工作,但我得到java.lang.Exception: No runnable methods错误,当我尝试运行测试套件。

想法?我已经成功地只能使用SuiteClass运行某些​​测试类,但尚未能够运行测试类别(@Category注释)。

import org.junit.experimental.categories.{Categories, Category} 
import org.junit.runners.Suite.SuiteClasses 
import org.scalatest.FunSuite 
import org.junit.runner.RunWith 
import org.scalatest.junit.JUnitRunner 

@RunWith(classOf[JUnitRunner]) 
@Category(Array(classOf[SlowTests])) 
class FunSuiteTest extends FunSuite with DemoHelpers { 
    test("demoTest1") { 
    println("\n\nrunning DemoTest1...\n\n") 
    } 
} 

@RunWith(classOf[JUnitRunner]) 
@Category(Array(classOf[SlowTests])) 
class FunSuiteTest2 extends FunSuite with DemoHelpers { 
    test("demoTest2") { 
    println("\n\nrunning DemoTest2...\n\n") 
    } 
} 

@RunWith(classOf[Categories]) 
@SuiteClasses(Array(classOf[SlowTests])) 
class testSuite { 

} 
+0

难道你不需要某个方法的'@Test'属性吗?像@Test def testSomeCode {...} – Noah

+0

是的,这是正确的。我最终用@Test注释和一切去完整的JUnit风格。 –

+0

如果问题解决了,您应该回答自己的问题并接受答案。 –

回答

2

这里翻译了Java进入Scala的逐行:

https://github.com/junit-team/junit/blob/master/doc/ReleaseNotes4.8.md

晴这意味着你要做阵列(classOf [类名]),删除 “公用” 关键字等

带有Scala插件的IntelliJ IDE可以提供很多建议。

+0

'@Category(Array(classOf [SlowTests])''注释只能应用于类,而不适用于单个方法。 – Noel