yorkville
yorkville

Reputation: 87

ScalaTest errors on assert and test in Intellij

I am fairly new to Scala and Intellij and brand new to ScalaTest. I have set up Intellij 14 and Scala 2.11.4 with the latest Scala plugin and everything works fine. I then tried to introduce ScalaTest and I am very confused. I downloaded the latest version of ScalaTest (scalatest_2.11-2.2.1.jar) from scalatest.org. I went into my project structure and selected "Modules", clicked the green plus sign and added scalatest_2.11-2.2.1.jar. All went well and I can see the scalatest jar in External Libraries in my project. When I created my first test it imported org.scalatest.Funsuite and the class extended FunSuite and all was well. I then tried a very simple test that I copied from the Internet.

import org.scalatest.FunSuite

class MyTest extends FunSuite {
    test("this is a test") {
        assert(true)
  }
}

I get 2 errors. It can not resolve the "assert" reference with that signature and for the "test" method it says unspecified value parameters Seq[Tag]: () => BoxedUnit.

I can see other method signatures for "assert" and "test" but I can not use the most basic ones.

Thanks for any help

Upvotes: 2

Views: 1588

Answers (1)

Spiro Michaylov
Spiro Michaylov

Reputation: 3571

While I didn't get exactly the same error messages, I had similar overall problems until I realized that you need two more JARs to use ScalaTest successfully: scala-reflect-2.11.4.jar and scala-xml-2.11-1.0.2.jar.

If you insist on doing this by hand you should also make sure that you have your tests in a directory that is marked as a "tests" directory -- so is highlighted in green: you can achieve this on the same "Modules" tab, but in the "Sources" sub-tab rather than "Dependencies". You also need to check that in the "Scope" column of the "Dependencies" sub-tab, the jars you added are marked as "Test" rather than "Compile".

If, on the other hand, you create an SBT project in IntelliJ rather than a regular Scala project, you could just add the following to your build.sbt:

libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.1" % "test"

Re-import the build.sbt when prompted, then you can start writing and running tests: all the dependencies and test directories are set up correctly and it all "just works". I just created an empty project this way and ran your example. It took about a minute from beginning to end.

Obviously you're facing a trade-off between managing JARs by hand and learning yet another tool, but at this point learning the very basics of SBT may be worth your while.

Upvotes: 2

Related Questions