How to run a package before a test

I have a scala compiler project. Some of the test cases depend on the generated jar file. Therefore, I always manually launch the β€œpackage” task before starting the β€œtest” task.

How can I add an SBT task that will perform the test task, but will depend on the package?

+7
source share
1 answer

sbt 0.12:

Add the following parameters to the project settings:

(test in Test) <<= (test in Test) dependsOn (Keys.`package` in Compile) 

This changes the test task for your project. But you can also define your own task:

 val myTestTask = TaskKey[Unit]("my-test-task", "runs package and then test") 

And then add this to your project settings:

 myTestTask <<= (test in Test) dependsOn (Keys.`package` in Compile) 

sbt 0.13:

Add the following parameters to the project settings:

 (test in Test) := { (Keys.`package` in Compile).value (test in Test).value } 

This changes the test task for your project. But you can also define your own task:

 val myTestTask = taskKey[Unit]("runs package and then test") 

And then add this to your project settings:

 myTestTask := { (Keys.`package` in Compile).value (test in Test).value } 
+7
source

All Articles