3

does somebody know why @Test annotated methods which are inherited from a Scala trait are not found by the JUnit 4 test runner? 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() {
 // ...
}
Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
Tim Friske
  • 2,012
  • 1
  • 18
  • 28
  • How are you running your tests? It may be an issue with the IDE rather than the test runner: http://www.manning-sandbox.com/thread.jspa?messageID=62087&tstart=0. – Aaron Novstrup Aug 06 '11 at 14:34
  • Hi Aaron, I try to run it through Eclipse JEE Indigo Release together with the Scala IDE 2.0.0.beta9. – Tim Friske Aug 06 '11 at 21:43

1 Answers1

1

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.

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171