I have a 0.13.7 SBT project, with several sub-projects.
One of them is called webapp
, and it has many JUnit
tests in webapp/src/test/
Finally, I've discovered, that I have to add the following settings to the subproject:
lazy val webapp = project
settings(
Seq(
projectDependencies ++= Seq(
....
"org.scalatest" %% "scalatest" % "2.2.2" % Test,
"junit" % "junit" % "4.11" % Test,
crossPaths := false,
"com.novocode" % "junit-interface" % "0.11" % Test
)
): _*
)
It is important to declare the junit-interface
dependency in the subproject, and in addition, to set to false the crossPaths
setting.
The clue has been given by this issue.
If the main project doesn't have JUnit
tests, then the needed test settings, don't need to be provided.
In addition, for knowing the failing method and the cause, we need this setting:
testOptions in Test := Seq(Tests.Argument(TestFrameworks.JUnit, "-a"))
This question about supporting JUnit in SBT has been asked multiple times with slightly different framings.
Multiple hits made it hard for me to find the simplest and most current answer.
This answer by @david.perez seems clear and works with current (2018) SBT 1.1.4.
(That particular question was about conflicting JUnit versions. The exclude("junit", "junit-dep")
may not be necessary.)
I'll also copy-paste the code here for quick access:
libraryDependencies ++= Seq(
"junit" % "junit" % "4.12" % Test,
"com.novocode" % "junit-interface" % "0.11" % Test exclude("junit", "junit-dep")
)