sbt没有找到junit测试

时间:2018-03-14 12:27:02

标签: java scala junit sbt

这是我的build.sbt

name := "tutu"
organization := "com.tutu"
version := "1.0"

// Enables publishing to maven repo
publishMavenStyle := true

// Do not append Scala versions to the generated artifacts
crossPaths := false

// This forbids including Scala related libraries into the dependency
autoScalaLibrary := false

assemblyJarName in assembly := "tutu.jar"
mainClass in assembly := Some(" com.tutu.tutuApplication")


assemblyMergeStrategy in assembly := {
  case x if Assembly.isConfigFile(x) =>
    MergeStrategy.concat
  case PathList(ps @ _*) if Assembly.isReadme(ps.last) || Assembly.isLicenseFile(ps.last) =>
    MergeStrategy.rename
  case PathList("META-INF", xs @ _*) =>
    (xs map {_.toLowerCase}) match {
      case ("io.netty.versions.properties" :: Nil) => MergeStrategy.discard
      case ("manifest.mf" :: Nil) | ("index.list" :: Nil) | ("dependencies" :: Nil) =>
        MergeStrategy.discard
      case ps @ (x :: xs) if ps.last.endsWith(".sf") || ps.last.endsWith(".dsa") =>
        MergeStrategy.discard
      case "plexus" :: xs =>
        MergeStrategy.discard
      case "services" :: xs =>
        MergeStrategy.filterDistinctLines
      case ("spring.schemas" :: Nil) | ("spring.handlers" :: Nil) =>
        MergeStrategy.filterDistinctLines
      case _ => MergeStrategy.deduplicate
    }
  case PathList("javax", "inject", xs @ _*) => MergeStrategy.last
  case _ => MergeStrategy.deduplicate
}



libraryDependencies += "io.dropwizard" % "dropwizard-core" % "1.2.2"
libraryDependencies += "com.squareup.okhttp3" % "okhttp" % "3.0.0-RC1"

libraryDependencies += "junit" % "junit" % "4.11" % Test
libraryDependencies += "io.dropwizard" % "dropwizard-testing" % "1.2.2" % Test

testOptions += Tests.Argument(TestFrameworks.JUnit, "-q")

我的项目结构是

  • SRC
    • ...
    • 测试
    • 的java
      • COM /短裙
      • API
      • 客户端
      • 分贝
      • 资源
        • PingTest.java

如果我跑

$ sbt test

它没有执行我的PingTest,但@Test是正确定义的。如何让sbt检测我的Java Test类?

1 个答案:

答案 0 :(得分:0)

您需要阅读有关junit-interface的this

简而言之,您需要添加依赖

"com.novocode" % "junit-interface" % "0.11" % Test

此外,当我在项目中解决类似问题时,我还需要添加

crossPaths := false

这是来自this问题评论。