I'm running sbt-assembly in order to build a single jar file that can be deployed elsewhere. I would like to run my tests against this jar file rather than against the local .class files. Running against the local .class files is the default with sbt test
but I want to test the jar instead (but without incorporating the test class files into the jar).
-
1Have a look at: stackoverflow.com/questions/16389446/….– Guillaume BelroseCommented Oct 17, 2014 at 14:02
-
1@TooTone I'm not sure that Spark is your use case, but maybe it can be interesting to you: eugenezhulenev.com/blog/2014/10/18/… I prepared example of running tests in standalone Spark cluster with assembled jar file– Eugene ZhulenevCommented Oct 19, 2014 at 1:45
-
@EugeneZhulenev I will look into that thankyou. It seems it might relate to my question here, also.– TooToneCommented Oct 20, 2014 at 10:36
Add a comment
|
1 Answer
To build assembly jar in test you need to configuration
import AssemblyKeys._
Project.inConfig(Test)(baseAssemblySettings)
jarName in (Test, assembly) := s"${name.value}-test-${version.value}.jar"
So now you can prepare uber-jar with test:assembly. However I don't know easy way to run tests from sbt with this jar. I would go for custom command, something like test:run-test-assembly that will do something like this internally
scala -classpath uber-jar-test.jar classpath scalatest-<version>.jar org.scalatest.tools.Runner -p compiled_tests
sbt-assembly is running tests during assembly phase, but I'm pretty sure it's doing it agains not yet packaged classes. Sou you probably want to exclude them from assembly phase with
test in (Test, assembly) := {}
-
thanks but including
scalatest
on the command line seems unnecessary (presumably it gets included automatically when working out the dependencies). And more seriously, when I runscala -classpath uber-jar-test.jar -classpath org.scalatest.tools.Runner -R target/scala-2.10/test-classes/
, the scalatest GUI pops up and correctly finds my 25 tests, but fails with ajava.lang.NoClassDefFoundError
(as the jar is assembled then all the classes ought to be there, right?)– TooToneCommented Oct 17, 2014 at 16:53 -
1Downvoting because this doesn't answer the question of running tests against an assembly jar; it answers how to build an assembly jar that includes tests. Commented Mar 30, 2017 at 2:22
-