Running scalatest tests in Eclipse


/ Published in: Scala
Save to your folder(s)

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)


Copy this code and paste it in your HTML
  1. package scalaunittest
  2.  
  3. import org.scalatest.FunSuite
  4. import org.scalatest.junit.JUnitRunner
  5. import org.junit.runner.RunWith
  6.  
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.