开发者

@Test method in Scala trait not found

开发者 https://www.devze.com 2023-03-26 14:06 出处:网络
does somebody know why @Test annotated methods which are inherited from a Scala trait are not found by the JUnit 4 test run开发者_JAVA百科ner? It gives me \"No JUnit tests found\".

does somebody know why @Test annotated methods which are inherited from a Scala trait are not found by the JUnit 4 test run开发者_JAVA百科ner? It gives me "No JUnit tests found".

class FooTests extends BarTesting

But the following modification works?

import junit.framework.TestCase

class FooTests extends TestCase with BarTesting

In the Scala trait BarTesting I defined methods with the following signature.

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


This is indeed a bug in Eclipse. You can raise as such if you like. http://www.assembla.com/spaces/scala-ide/tickets.

When you extend TestCase the test is being run because it starts with test, not because of the annotation. There was a problem with recognition of annotations, which is how the junit stuff works, and I haven't looked to see if it is fixed yet to make the junit stuff work.

Your best bet is to:

  1. Raise the bug against scala-ide
  2. Add @RunWith[classOf[JUnit]) to your class

The following works:

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

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

And I'll try and fix the bug.

EDIT: In the latest versions of scala-ide (as of 9 November 2011), this now works.

0

精彩评论

暂无评论...
验证码 换一张
取 消