How do I run a scala ScalaTest in IntelliJ idea?

Matteo Caprari picture Matteo Caprari · Dec 22, 2010 · Viewed 25.2k times · Source

I'm trying to run a scala flatspec test within Intellij IDEA (latest community build, with latest Scala plugin), but I keep getting "Empty test suite" errors.

I tried using the normal "run" menu on right click, but it does not work. I also tried creating a new ScalaTest configuration, but still the runner is not picking up the tests.

I was able to use JScalaTest with unit, but I'd really prefer to use flatspec syntax.

UPDATE: annotating the class with @RunWith(classOf[JUnitRunner]) does not help either

Thanks!

class SampleTestSpec extends FlatSpec with ShouldMatchers {
    "test" should "fail" in {
        "this" should equal ("that")
    }
}

UPDATE: Switching from ScalaTest to Spec, solved the problem. I still prefer ScalaTest with FlatSpec, but this is good enough. Code that works:

import org.specs._
object SampleTestSpec extends Specification {
    "'hello world' has 11 characters" in {
     "hello world".size must be equalTo(113)
  }
  "'hello world' matches 'h.* w.*'" in {
     "hello world" must be matching("h.* w.*")
  }
}

-teo

Answer

lysium picture lysium · Jul 25, 2013

If IntelliJ does not pick up the tests automatically, you can do the following:

In the Run Configuration, create a ScalaTest run configuration and set up its "Test kind" to "All in package" and its "Test Package" to the package that contains your tests.