111

Is there a way to build tests with SBT without running them?

My own use case is to run static analysis on the test code by using a scalac plugin. Another possible use case is to run some or all of the test code using a separate runner than the one built into SBT.

Ideally there would be a solution to this problem that applies to any SBT project. For example, Maven has a test-compile command that can be used just to compile the tests without running them. It would be great if SBT had the same thing.

Less ideal, but still very helpful, would be solutions that involve modifying the project's build files.

4 Answers 4

185

Just use the Test / compile command.

2
  • 4
    does this compile tests and the code? or just the tests?
    – Jwan622
    Commented May 31, 2018 at 18:04
  • 1
    @Jwan622 the former
    – juanchito
    Commented May 13, 2022 at 13:22
27

Test/compile works for compiling your unit tests.

To compile integration tests you can use IntegrationTest/compile.

Another hint to continuously compile on every file change: ~Test/compile

11

We have a build.sbt file that is used for multiple projects. Doing sbt test:compile compiled the tests for every single project and took over 30 minutes.

I found out I can compile only the tests for a specific project named xyz by doing:

sbt xyz/test:compile
11

Using sbt version 1.5.0 and higher test:compile returns deprecation warning.

Use Test / compile.

(docs)

Not the answer you're looking for? Browse other questions tagged or ask your own question.