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).
Asked
Active
Viewed 2,795 times
4

TooTone
- 7,129
- 5
- 34
- 60
-
1Have a look at: http://stackoverflow.com/questions/16389446/compile-tests-with-sbt-and-package-them-to-be-run-later. – Guillaume Belrose Oct 17 '14 at 14:02
-
1@TooTone I'm not sure that Spark is your use case, but maybe it can be interesting to you: http://eugenezhulenev.com/blog/2014/10/18/run-tests-in-standalone-spark-cluster/ I prepared example of running tests in standalone Spark cluster with assembled jar file – Eugene Zhulenev Oct 19 '14 at 01:45
-
@EugeneZhulenev I will look into that thankyou. It seems it might relate to my question here, also. – TooTone Oct 20 '14 at 10:36
1 Answers
1
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) := {}

Eugene Zhulenev
- 9,714
- 2
- 30
- 40
-
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 run `scala -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 a `java.lang.NoClassDefFoundError` (as the jar is assembled then all the classes ought to be there, right?) – TooTone Oct 17 '14 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. – Eron Wright Mar 30 '17 at 02:22
-