Posted By

tedg on 10/30/13


eclipse Scala unit-test scalatest

Versions (?)

Running scalatest tests in Eclipse

 / Published in: Scala

This is a minimum scalatest suite that we can run inside Eclipse.

One is supposed to be able to run JUnit tests in Eclipse by right clicking the test class and select, from context menu, Run As | JUnit Test. However, if a scalatest is added without the @RunWith(classOf[JUnitRunner]), the Eclipse context menu item Run As | JUnit Test is not available. The only menu item under Run As is Run Configurations ....

Adding the @RunWith(classOf[JUnitRunner]) triggers Eclipse to add two menu item, JUnit Test, and Scala JUnit Test to be added under Run As on the context menu. Removing the annotation, will only trigger Eclipse to remove the JUnit Test item, with the Scala JUnit Test item remained. It looks like a bug. (It is about Scala IDE 3.0.1)

  1. package scalaunittest
  3. import org.scalatest.FunSuite
  4. import org.scalatest.junit.JUnitRunner
  5. import org.junit.runner.RunWith
  7. @RunWith(classOf[JUnitRunner]) // Run As | JUnit Test
  8. class ListSuite extends FunSuite {
  9. test("list length") {
  10. val ls = List(2, 3, 4)
  11. assert(ls.length == 3)
  12. }
  13. }

Report this snippet  

You need to login to post a comment.