Aaron Shaver
Aaron Shaver

Reputation: 494

JUnit test categories in Scala?

I got it working! I literally translated the Java here into Scala line by line:

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

Mostly it meant doing Array(classOf[ClassName]), removing "public" keywords, etc. My IntelliJ IDE helped a lot with suggestions.


I want to be able to run categories of tests, so I might tag one class of tests as "Version2dot3" and "SlowTest" and then be able to run just "slow tests", or run "slow tests AND 2.3 tests".

I've been trying to adapt this article to my Scala tests:

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

I have a basic shell setup that almost works, but I'm getting java.lang.Exception: No runnable methods errors when I try to run the testSuite.

Ideas? I've successfully been able to run only certain test classes with SuiteClasses, but have not been able to run categories of tests (@Category annotation).

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 {

}

Upvotes: 5

Views: 1111

Answers (1)

Aaron Shaver
Aaron Shaver

Reputation: 494

Translate the Java here into Scala line by line:

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

Mostly it means doing Array(classOf[ClassName]), removing "public" keywords, etc.

The IntelliJ IDE with the Scala plugin helps a lot with suggestions.

Upvotes: 2

Related Questions