如何使用SBT运行JUnit4.11测试用例?
我在build.sbt中有以下内容:如何使用SBT运行JUnit4.11测试用例?,junit,sbt,Junit,Sbt,我在build.sbt中有以下内容: libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test" libraryDependencies += "junit" % "junit" % "4.11" % "test" 我注意到junit接口0.10依赖于junit dep 4.10。这使得不可能编译使用assertNotEquals的测试,这是在junit4.11中引入的 如何使用SBT运行JUnit
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test"
libraryDependencies += "junit" % "junit" % "4.11" % "test"
我注意到junit接口0.10依赖于junit dep 4.10。这使得不可能编译使用assertNotEquals的测试,这是在junit4.11中引入的
如何使用SBT运行JUnit 4.11测试用例?使用JUnit接口0.11以避免对JUnit dep的依赖:
libraryDependencies += "junit" % "junit" % "4.12" % "test"
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
更新:junit接口0.11通过依赖junit而不是junit-dep使其可靠。我会这样做:
libraryDependencies ++= Seq(
"junit" % "junit" % "4.11" % Test,
"com.novocode" % "junit-interface" % "0.11" % Test
exclude("junit", "junit-dep")
)
通过排除我们不想要的东西,它不会干扰我们。这与订购无关。junit接口0.11-SNAPSHOT似乎可以做到这一点,但我在任何地方都找不到发布的版本。您使用的SBT版本是什么?当您使用
force()
到junit
依赖关系时会发生什么?我使用的是sbt 0.13.1。我还没有试过force()
。我找到了一个不同的解决办法。我现在就发布答案。关于如何依靠类路径排序向SBT添加JUnit支持的相关问题是一种非常脆弱的处理方法。@Joekerney我完全同意。这是一个解决办法。junit接口0.11似乎已修复此问题。