我在Play Framework
应用程序中运行单元测试时遇到问题。
我目前正在使用Play v 2.6.11
和sbt 0.13.17
。测试过去一直有效,但似乎现在sbt
无法执行它们。
如果我只是运行sbt test
,我会No tests were executed.
。如果我使用sbt
启动sbt --debug
,我会收到更详细的日志,其中包含以下内容:
[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...
这是我的build.sbt
文件:
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()尝试添加
crossPaths := false
自从我在Missing Implementations
上看到该消息后,我已将此消息添加到我的build.sbt
(通过各种Google搜索):
"org.scalatest" %% "scalatest" % "3.0.5" % Test,
"com.novocode" % "junit-interface" % "0.11" % Test,
"org.exparity" % "hamcrest-date" % "2.0.0" % Test
但没有运气。我整个上午都遇到过各种Stackoverflow线程和github问题this,this或this
如果有人对如何调试这种情况有一些想法。
答案 0 :(得分:1)
就我而言,这有效:
打开sbt控制台:sbt
运行测试:testOnly *
或test *
因此添加*
解决了问题。
答案 1 :(得分:1)
如果您正在运行JUnit测试,请将以下内容添加到build.sbt
:
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v")
可能是JUnit测试确实正在运行,但日志事件处于DEBUG
级别,因此您无法看到它们。根据{{3}} -v
选项,将其记录在INFO
级别:
Log"测试运行开始" /"测试开始" /"测试运行结束"事件 在日志级别"信息"而不是" debug"。
在我的机器设置-v
选项中,我在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
虽然没有-v
测试选项,但没有输出。