Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt skip tests in subproject unless running from within that project?

Tags:

scala

sbt

I have an SBT project with multiple subprojects. One of the subprojects have tests that I don't want to run unless I explicitly do something like ";project xyz ;test-only". So, if my project structure is:

main main/abc main/def main/xyz

Ideally, running "test" in main would execute any tests in main, main/abc, and main/def projects, but not main/xyz.

I tried to add a test filter in the build file for the main class that excludes all tests in main/xyz (by package name), then adding a separate build.sbt file in the main/xyz project to add them back, but this still results in the tests being executed from the top-level project...

like image 882
jxstanford Avatar asked Mar 24 '12 22:03

jxstanford


1 Answers

"Aggregation" is the name of the feature that makes test execute on other projects (known as aggregated projects or "execution dependencies") as well as the current one. You can find more information on the Multi-Project Builds page.

I would create a custom task in the "main" project that depends on the tasks you want to run. For example,

myTestTask <<= Seq(
  test in (main, Test),
  test in (abc, Test),
  test in (deff, Test)
).dependOn

where val myTestTask = TaskKey[Unit]("my-test-task") and main, abc, and deff are references to your Projects.

Aggregation is only applied to the top-level task specified on the command line. So, if you call my-test-task, that will be the only task aggregated (in this case, it won't be defined on any subprojects, so no tasks get added through aggregation). In particular, its dependencies, the explicitly listed test tasks, don't get aggregated. The consequence is that test in xyz doesn't get executed when you call my-test-task.

Finally, note that you can say xyz/test-only to run test-only for the xyz project without changing to that project.

like image 174
Mark Harrah Avatar answered Sep 29 '22 06:09

Mark Harrah