Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Resolve Symbol "Scalatest"

I am trying to use scalatest, but Intellij cannot recognize:

import org.scalatest._

Here is my build.sbt file, located in the same directory as my scalatest.jar file.

scalaVersion := "2.11.2"

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"

Thanks

like image 575
nietsnegttiw Avatar asked Jul 14 '15 20:07

nietsnegttiw


People also ask

How do I ignore ScalaTest?

When you mark a test class with a tag annotation, ScalaTest will mark each test defined in that class with that tag. Thus, marking the SetSpec in the above example with the @Ignore tag annotation means that both tests in the class will be ignored.

How do I add ScalaTest to IntelliJ?

To install Scala plugin, press Ctrl+Alt+S , open the Plugins page, browse repositories to locate the Scala plugin, click Install and restart IntelliJ IDEA. Now you can successfully check out from VCS, create, or import Scala projects.

What is FunSuite in Scala?

A suite of tests in which each test is represented as a function value. The “ Fun ” in FunSuite stands for “function.” Here's an example FunSuite : import org.scalatest.FunSuite.


1 Answers

So you have by convention two source folders:

src/main/scala/...
src/test/scala/...

The first is shown blue, the second green in IntelliJ IDEA. The library dependencies in sbt are associated with either of these, so

"org.foo" % "bar_2.11" % "1.2.3"

Is a main dependency, available to main sources (and also test, because test depends on main). And

"org.foo" % "bar_2.11" % "1.2.3" % "test"

Is a test dependency, only available to test sources. The idea is that these are libraries which are not required for your product, but only to run the unit tests.


In your example, Scala-Test is only available to test sources, so trying to import it from main sources will fail.

like image 125
0__ Avatar answered Oct 13 '22 13:10

0__