SBT can't find JUnit tests to run

Viewed 897

I want to use JUnit 4.12 as my testing framework in an SBT project. I have added these dependencies to my build.sbt:

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

And my project structure is like this:

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

I have not added Play framework plugin to this project. But in another project I use Play framework with same dependencies and even same structure and tests run.

I have both sbt and activator installed on my MacOS and neither of them work. I tried these commands:

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

I used sbt v0.13.8 + junit v4.12 + play framework v2.5.8 + scala v2.11.7

Edit: My build.sbt is this:

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 Answers
Related