SBT无法找到要运行的JUnit测试

时间:2017-09-16 13:18:48

标签: java junit playframework sbt junit4

我想在一个SBT项目中使用JUnit 4.12作为我的测试框架。我已将这些依赖项添加到build.sbt

"junit" % "junit" % "4.12" % Test,
"com.novocode" % "junit-interface" % "0.11" % Test exclude("junit", "junit-dep")

我的项目结构是这样的:

.
├── build.sbt
├── project
│   ├── build.properties
│   └── plugins.sbt
├── src
│   ├── main
│   │   └── java
│   └── test
│       └── java

我没有在这个项目中添加Play框架插件。但在另一个项目中,我使用具有相同依赖关系的Play框架和甚至相同的结构并运行测试。

我的MacOS上安装了sbtactivator,但两者都无法正常工作。我尝试了这些命令:

sbt test
sbt testOnly path.to.class
activator test
activator testOnly path.to.class

我使用了sbt v0.13.8 + junit v4.12 + play framework v2.5.8 + scala v2.11.7

修改:我的build.sbt就是这样:

organization := "ir.iais"

name := "play-commons"

lazy val play_commons = project in file(".")

version := iaisVersion

credentials += Credentials(Path.userHome / ".sbt" / ".credentials")

credentials += Credentials(Path.userHome / ".sbt" / ".credentials.deploy")

val iaisVersion = "1.1.1-SNAPSHOT"

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  javaWs,
  cache,
  filters,
  "com.auth0" % "java-jwt" % "3.1.0",
  "org.mindrot" % "jbcrypt" % "0.3m",
  "be.objectify" %% "deadbolt-java" % "2.5.0",
  "org.funktionale" % "funktionale-all" % "1.1",
  "com.google.code.findbugs" % "jsr305" % "3.0.2",
  "ir.iais.utilities" % "g-utils" % iaisVersion % Optional,
  "com.typesafe.play" %% "play-mailer" % "3.0.0-M1" % Optional,
  "org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.4.1",
  // https://mvnrepository.com/artifact/com.lmax/disruptor
  "com.lmax" % "disruptor" % "3.3.6",
  "org.projectlombok" % "lombok" % "1.16.18" % "provided",
  /* Start Hibernate dependencies */
  "org.hibernate" % "hibernate-core" % "5.2.2.Final" % Optional,
  /* End Hibernate dependencies */
  /* Start Test Dependencies */
  "junit" % "junit" % "4.12" % Test,
  "com.novocode" % "junit-interface" % "0.11" % Test exclude("junit", "junit-dep")
  /* End Test Dependencies */
).map(_.exclude("jta", "javax.transaction"))
  .map(_.exclude("dom4j", "dom4j"))
  .map(_.exclude("org.springframework", "spring-context"))
  .map(_.exclude("org.springframework", "spring-expression"))
  .map(_.exclude("org.springframework.data", "spring-data-jpa"))

libraryDependencies ++= Seq(
  "org.springframework" % "spring-context" % "5.0.0.RC3",
  "javax.inject" % "javax.inject" % "1",
  "org.springframework.data" % "spring-data-jpa" % "2.0.0.RC2",
  "org.springframework" % "spring-expression" % "5.0.0.RC3"
)

//unmanagedResourceDirectories in Test <+= baseDirectory(_ / "target/web/public/test")

//javaSource in Test := baseDirectory.value / "test"

//fork in Test := false

scalacOptions ++= Seq("-encoding", "UTF-8")

javacOptions ++= Seq("-encoding", "UTF8")

javaOptions += "-Xdoclint:none"

scalacOptions += "-target:jvm-1.8"

javaOptions in Test ++= Seq(
  "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9998",
  "-Xms512M",
  "-Xmx1536M",
  "-Xss1M",
  "-XX:MaxPermSize=384M"
)
val javacOpts = Seq("-source", "1.8", "-target", "1.8")
javacOptions ++= javacOpts
javacOptions in Test ++= javacOpts

initialize := {
  val _ = initialize.value // run the previous initialization
  val required = "1.8"
  val current = sys.props("java.specification.version")
  assert(current == required, s"Unsupported JDK: java.specification.version $current != $required")
}

updateOptions := updateOptions.value.withCachedResolution(true)

// enable publishing the jar produced by `test:package`
publishArtifact in(Test, packageBin) := true

// enable publishing the test sources jar
publishArtifact in(Test, packageSrc) := true

// disable publishing the main API jar
publishArtifact in(Compile, packageDoc) := false

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

0 个答案:

没有答案