Question

Let's say I have a typical framework application in Scala using the standard folder structure. I want to run my compiled tests on a CI server - those tests live in the /tests folder.

When I run the scalatest runner as detailed here: http://www.scalatest.org/user_guide/using_the_runner with the following command-line command:

scala -classpath /home/vagrant/.ivy2/ org.scalatest.tools.Runner -R target

I get the following error:

java.lang.NoClassDefFoundError: scala/concurrent/duration/Duration
    at org.scalatest.tools.Runner$.<init>(Runner.scala:741

I understand it's telling me that it can't find the duration class which is required as part of the tests. I also understand that it's probably because that class is not on the classpath, but I don't how to specify the classpath to pass to the runner.

I have tried specifying a classpath of "target" like the following:

scala -classpath /home/vagrant/.ivy2/cache/org.scalatest/scalatest_2.10/jars/scalatest_2.10-2.0.M8.jar:target org.scalatest.tools.Runner -R target

The "target" folder is where the compiled application and tests are put for the play framework. I'm running that command from the root of the project so target is a valid file path.

It looks like I have a fundamental gap in my understanding of how the classpath works.

EDIT I had some success by manually adding the scala lang jar to the classpath which contains the duration class. But how can I add all jars to the classpath? Is there wildcard syntax?

scala -classpath "/home/vagrant/.ivy2/cache/org.scalatest/scalatest_2.10/jars/scalatest_2.10-2.0.M8.jar:/home/vagrant/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.10.3.jar" org.scalatest.tools.Runner -R target
java.lang.IncompatibleClassChangeError: Found class scala.collection.mutable.ArrayOps, but interface was expected
Was it helpful?

Solution

Here is how you can use Runner to run a test suite:

Compile tests with SBT and package them to be run later

and here is how to easily add multiple jar files to your classpath:

Run scala console with play 2.2 jars

OTHER TIPS

Get classpath of all dependencies with:

DEPS=$(sbt --error "export compile:dependencyClasspath")

And then run tests:

java -cp "<path to scalatest.jar>":$DEPS org.scalatest.tools.Runner -R target

where <path to scalatest.jar> is something like /home/user/project/.ivy2/cache/org.scalatest/scalatest_2.11/bundles/scalatest_2.11-2.2.6.jar.

Yes, you can use java, not scala, because $DEPS already contains all Scala libraries.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top