How to add scalatest to project?

I'm trying to work on a Scala project in IDEA, and need to add the scalatest library to the dependencies. However, the things that I've tried in the "Project Structure" screen have not worked, and I would like to know the best way to add in a library such as scalatest, so that it becomes accessible to my testing code.

I apologize for posting this to the general IDEA group, but when I attempted to post to the scala-specific group, I got a permissions error and a very nonobvious error message, which did not enable me to figure out what to do to post to the scala-specific group.


1 comment
Comment actions Permalink

I am not a Scala developer but I gave it a try. I followed the following steps:
* Checked to see if the scala plugin is installed. It was not so I installed it.
* Check how to setup the Idea IntelliJ IDE for scala.  See here for further details but mainly I had to attach the scala framework support via select the module and choose the Add Framework Support through contextual menu item. In the dialog I did choose scala and select the SCALA_HOME dir.
* The project is maven-based because amongst the other its powerful build-project supports is resolving the dependencies:
* Added some repos and  dependencies for scala and scala test as per below:


            <name>Scala-Tools Maven2 Repository</name>



* Created the following scalatest test:

import org.scalatest.FunSuite;
import scala.Int;
import scala.collection.mutable.Stack;

class ExampleTest extends FunSuite {

    test("pop is invoked on a non-empty stack") {
        val stack = new Stack[Int]
        val oldSize = stack.size
        val result = stack.pop()
        assert (result == 2)
        assert (stack.size == oldSize - 1)

* Some configuration are required:

- Settings > Compiler > Scala Compiler > Javac then ScalaC

- Settings > Compiler > Annotation Processors > Select the module > uncheck Enable annotation processing (I am not so sure this is indeed required with previous selection on)

* Right click on ExampleTest and choose Run ExampleTest


* Following these steps I've noticed an Idea intelliJ issue. The  'javac, then scalac'  Join compilation setting is not retained (both Join Compilation are unchecked).

* Running mvn clean test I got the following strange output but I think this is related to test surefire plugin and scala test (further investigation is required: maybe attach a scalatest plugin to test goal??!!)

I hope this help




Please sign in to leave a comment.