Run JUnit tests with SBT

后端 未结 2 2062
南旧
南旧 2020-12-01 16:26

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/

2条回答
  •  渐次进展
    2020-12-01 16:40

    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"))
    

提交回复
热议问题