Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run a scala ScalaTest in IntelliJ idea?

Tags:

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

like image 284
Matteo Caprari Avatar asked Dec 22 '10 11:12

Matteo Caprari


People also ask

How do I use Scala code in IntelliJ?

To start working with Scala in IntelliJ IDEA you need to download and enable the Scala plugin. If you run IntelliJ IDEA for the first time, you can install the Scala plugin when IntelliJ IDEA suggests downloading featured plugins. Otherwise, you can use the Settings | Plugins page for the installation.

How do I open an existing Scala project in IntelliJ?

Make sure you have the scala plugin for intellij. Go file>new>'project from existing source', select your project to import. Go to build. sbt and there should be a prompt to import the packages.


1 Answers

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.

like image 61
lysium Avatar answered Oct 06 '22 19:10

lysium