Skip to content

Instantly share code, notes, and snippets.

@erikfried
Last active December 22, 2015 10:59
Show Gist options
  • Save erikfried/6462883 to your computer and use it in GitHub Desktop.
Save erikfried/6462883 to your computer and use it in GitHub Desktop.
Run tests locally with sbt in maven project.

What does sbt have that maven does not?

  1. Continuous compilation, that is files are compiled and tested upon file change. Just run any target with ~, eg sbt ~test
  2. Sheer speed. The full test execution takes about half the time compared to maven.
  3. test-quick - An sbt target that only runs tests that either a) failed in the previous run b) have not run before or c) Have recompiled dependencies.

How?

javacOptions ++= Seq("-encoding", "UTF-8") //Support utf8 in java source files.
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test" //Sbt does not recognize junit tests out-of-the-box, so we have to add this dep.
libraryDependencies += "org.scala-lang" % "scala-library" % "2.9.2" % "compile-internal" //You need to put scala on classpath to run 'sbt console'
testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v", "-s") //Makes console output a bit prettier.
parallelExecution in Test := false //Some of our (embedded-) database tests cannot be run in parallel due to locking during setUp.
addSbtPlugin("com.github.shivawu" % "sbt-maven-plugin" % "0.1.2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment