tl; dr Use testResultLoggerwith a custom logger of test results, TestsFailedExceptionwhich, in turn, sets the non- exit code 0.
Just noticed that I missed this requirement: βto avoid a change build.sbt. You can use any other file *.sbt, say, exitcodezero.sbtor ~/.sbt/0.13/default.sbtwith a custom one testResultLogger.
It turns out that starting with version 0.13.5, there is a way to have this behavior - see the Added parameter 'testResultLogger', which allows you to configure the test report in which it was born testResultLogger.
> help testResultLogger
Logs results after a test task completes.
TestResultLogger.SilentWhenNoTests, testResultLogger:
results.overall match {
case TestResult.Error | TestResult.Failed => throw new TestsFailedException
case TestResult.Passed =>
}
, TestsFailedException TestsFailedException , :
[error] Failed: Total 3, Failed 1, Errors 0, Passed 2
[error] Failed tests:
[error] HelloWorldSpec
[error] (test:test) sbt.TestsFailedException: Tests unsuccessful
, . build.sbt 0:
testResultLogger in (Test, test) := new TestResultLogger {
import sbt.Tests._
def run(log: Logger, results: Output, taskName: String): Unit = {
println("Exit code always 0...as you wish")
}
}
TestResultLogger.SilentWhenNoTests.run TestResultLogger.SilentWhenNoTests.run .
β failing-tests-dont-break-build xsbt test; echo $?
JAVA_HOME=/Library/Java/JavaVirtualMachines/java8/Contents/Home
SBT_OPTS= -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -Dfile.encoding=UTF-8
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to failing-tests-dont-break-build (in build file:/Users/jacek/sandbox/failing-tests-dont-break-build/)
[info] HelloWorldSpec
[info]
[info] The 'Hello world' string should
[info] x contain 11 characters
[error] 'Hello world' doesn't have size 12 but size 11 (HelloWorldSpec.scala:7)
[info]
[info] + start with 'Hello'
[info] + end with 'world'
[info]
[info] Total for specification HelloWorldSpec
[info] Finished in 15 ms
[info] 3 examples, 1 failure, 0 error
Exit code always 0...as you wish
[success] Total time: 1 s, completed Sep 19, 2014 9:58:09 PM
0