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.

Thanks,
Ken

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 http://confluence.jetbrains.net/display/SCA/Getting+Started+with+IntelliJ+IDEA+Scala+Plugin 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:

...

    <properties>
        <scala.version>2.9.1-1</scala.version>
        <scalatest.version>1.8</scalatest.version>
    </properties>
...
    <repositories>
        <repository>
            <id>scala-tools.org</id>
            <name>Scala-Tools Maven2 Repository</name>
            <url>http://scala-tools.org/repo-releases</url>
        </repository>
        <repository>
            <id>sonatype</id>
            <name>Sonatype</name>
            <url>http://repository.sonatype.org/content/groups/public/</url>
        </repository>
    </repositories>

...

<build>
        <sourceDirectory>src/main/scala</sourceDirectory>
        <testSourceDirectory>src/test/scala</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <scalaVersion>${scala.version}</scalaVersion>
                </configuration>
            </plugin>
        </plugins>

</build>
* 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]
        stack.push(1)
        stack.push(2)
        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

Notes:

* 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

Regards

jtonic

0

Please sign in to leave a comment.