3

I'm having an issue with running my unit tests in a Play Framework application. I'm currently using v 2.6.11 of Play and sbt 0.13.17. Tests have worked in the past, but It seems that now sbt cannot execute them.

If I simply run sbt test I get No tests were executed.. If I start sbt with sbt --debug I get a more verbose log with the following:

[debug] [naha] . [debug] [naha] All member reference dependencies will be considered within this context. [debug] [naha] New invalidations: [debug] [naha] Set() [debug] [naha] Initial set of included nodes: Set() [debug] [naha] Previously invalidated, but (transitively) depend on new invalidations: [debug] [naha] Set() [debug] [naha] All newly invalidated sources after taking into account (previously) recompiled sources:Set() [debug] Copy resource mappings: [debug] [debug] Framework implementation 'org.scalacheck.ScalaCheckFramework' not present. [debug] Framework implementation 'org.specs2.runner.Specs2Framework' not present. [debug] Framework implementation 'org.specs2.runner.SpecsFramework' not present. [debug] Framework implementation 'org.specs.runner.SpecsFramework' not present. [debug] Subclass fingerprints: List((org.scalatest.Suite,false,org.scalatest.tools.Framework$$anon$1@1883984e), (junit.framework.TestCase,false,com.novocode.junit.JUnit3Fingerprint@420f0739)) [debug] Annotation fingerprints: List((org.scalatest.WrapWith,false,org.scalatest.tools.Framework$$anon$2@453e6a3d), (org.junit.runner.RunWith,false,com.novocode.junit.RunWithFingerprint@7fb29b6c), (org.junit.Test,false,com.novocode.junit.JUnitFingerprint@7760adb)) [debug] javaOptions: List() [debug] Forking tests - parallelism = false [info] ScalaTest [info] Run completed in 38 milliseconds. [info] Total number of tests run: 0 [info] Suites: completed 0, aborted 0 [info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0 [info] No tests were executed. [debug] Summary for JUnit not available. [debug] Forcing garbage collection...

This is my build.sbt file:

lazy val root = (project in file("."))
  .enablePlugins(PlayJava,PlayEbean)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  javaJdbc,
  javaWs,
  javaJpa,
  filters,
  guice,
  // Bunch of Dependencies
)

dependencyOverrides ++= Set(
  "io.ebean" % "ebean" % "11.14.3" withSources()
)

// Remove dependencies because of Multiple Bindings to SLF4J
excludeDependencies += "org.slf4j" % "slf4j-log4j12"
excludeDependencies += "org.log4j" % "log4j"

// Don't know why But activator stage started to complain while Compiling
// http://stackoverflow.com/questions/22974766/play2-play-stage-command-fails-with-not-found-type-setupcontext
sources in doc in Compile := List()

I've tried adding crossPaths := false as per this thread in Github

Since I saw that message on Missing Implementations I've added this to my build.sbt (through various google searches):

"org.scalatest" %% "scalatest" % "3.0.5" % Test, "com.novocode" % "junit-interface" % "0.11" % Test, "org.exparity" % "hamcrest-date" % "2.0.0" % Test

But without luck. I've been at it all morning in various Stackoverflow threads and github issues this, this or this

If any one has some ideas on how I can debug this situation.

Pedro Rio
  • 1,444
  • 11
  • 16

2 Answers2

2

In my case this worked:

Open sbt console: sbt

Run the tests: testOnly * or test *

So adding the * fixed the problem.

pme
  • 14,156
  • 3
  • 52
  • 95
  • Thanks for pitching in. But unfortunately it did not work. `test *` is unrecognized by `sbt` `testOnly *` is executed, but no tests are run – Pedro Rio Jun 11 '18 at 15:00
  • have you tried `testOnly *Test*` or something else that matches a testname? – pme Jun 11 '18 at 16:42
  • I tried `testOnly *`, `testOnly com.package.*` `testOnly com.*` and `testOnly com.package.ClassWithJunitTest*` – Pedro Rio Jun 11 '18 at 21:05
2

If you are running JUnit tests add the following to build.sbt:

libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v")

It might be the case that JUnit tests are indeed running, but the log events are at DEBUG level so you cannot see them. According to docs -v option logs them at INFO level:

Log "test run started" / "test started" / "test run finished" events on log level "info" instead of "debug".

On my machine setting -v option gives me the following output in sbt:

[info] Test run started
[info] Test com.gu.identitycommon.clickthrough.TokenServiceTest.shouldFlagInvalidPasswordResetTokens started
[info] Test com.gu.identitycommon.clickthrough.TokenServiceTest.shouldEndcodeAndDecodeActivationToken started
[info] Test com.gu.identitycommon.clickthrough.TokenServiceTest.shouldDecoedToNullUserGroupIfNoneProvidedInActivationToken started
[info] Test com.gu.identitycommon.clickthrough.TokenServiceTest.shouldRecognizeValidPasswordResetTokens started
[info] Test run finished: 0 failed, 0 ignored, 4 total, 0.276s
[info] Test run started

while without -v test option there is no output.

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
  • Thanks for pitching in, without much explanation things started working again (I did clean, cleanFiles, compile, stage) and in a mix of that, things started working (didn't need to try your solution). But I'm upvoting it because I might need it in the future. – Pedro Rio Jun 16 '18 at 16:14