2011-08-06 188 views
3

是否有人知道为什么@Test注释方法继承从Scala的特质是没有发现由JUnit 4测试亚军?它给了我“没有找到JUnit测试”。@Test方法没有找到

class FooTests extends BarTesting 

但是,以下修改的作品?

import junit.framework.TestCase 

class FooTests extends TestCase with BarTesting 

在斯卡拉特质BarTesting我定义了具有以下签名的方法。

@Test 
final def testBar() { 
// ... 
} 
+0

你是如何运行你的测试?这可能是IDE而不是测试运行者的问题:http://www.manning-sandbox.com/thread.jspa?messageID=62087&tstart=0。 –

+0

嗨,Aaron,我尝试通过Eclipse JEE Indigo Release和Scala IDE 2.0.0.beta9一起运行它。 –

回答

1

这确实是Eclipse中的一个bug。如果你喜欢,你可以这样举。 http://www.assembla.com/spaces/scala-ide/tickets

当您扩展TestCase时,测试正在运行,因为它以测试开始,而不是因为注释。认识注解存在一个问题,这就是junit的工作原理,我还没有看到它是否是固定的,还没有使junit的工作成功。

你最好的选择是:

  1. 提高对斯卡拉-IDE的bug
  2. 添加@RunWith [classOf [JUnit的])上您的课

以下工作:

trait BarTesting { 
    @Test final def testBar() { 
    println("Hello world") 
    } 
} 

@RunWith(classOf[JUnit4]) 
class FooTesting extends BarTesting { 
} 

我会尝试修复这个错误。

编辑:在最新版本的scala-ide(截至2011年11月9日),现在可以工作。