Search code examples
unit-testingscalaintellij-ideascalatest

How do I run a scala ScalaTest in IntelliJ idea?


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


Solution

  • I've been running it like this (however I do find it a little verbose and it can probably be cut down):

    @RunWith(classOf[JUnitSuiteRunner])
    class AuthorisationParserRunAsTest extends JUnit4(AuthorisationParserSpec)
    object AuthorisationParserSpec extends Specification {
      ...
    }