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…
“Aggregation” is the name of the feature that makes
testexecute 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,
where
val myTestTask = TaskKey[Unit]("my-test-task")andmain, abc, and deffare 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 listedtesttasks, don’t get aggregated. The consequence is thattest in xyzdoesn’t get executed when you callmy-test-task.Finally, note that you can say
xyz/test-onlyto runtest-onlyfor thexyzproject without changing to that project.