【问题标题】:No tests were executed (Play Framework)未执行任何测试(Play Framework)
【发布时间】:2018-06-12 01:16:58
【问题描述】:

我在 Play Framework 应用程序中运行单元测试时遇到问题。 我目前正在使用 v 2.6.11 of Play 和 sbt 0.13.17。过去测试有效,但现在sbt 似乎无法执行。

如果我只是运行sbt test,我会得到No tests were executed.。如果我以sbt --debug 开头sbt,我会得到一个更详细的日志,其中包含以下内容:

[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 文件:

懒惰的val root =(文件中的项目(“。”)) .enablePlugins(PlayJava,PlayEbean) scalaVersion := "2.11.7" libraryDependencies ++= Seq( javaJdbc, javaWs, javaJpa, 过滤器, 吉斯, // 一堆依赖 ) 依赖覆盖 ++= 设置( "io.ebean" % "ebean" % "11.14.3" withSources() ) // 由于对 SLF4J 的多个绑定而删除依赖项 excludeDependencies += "org.slf4j" % "slf4j-log4j12" excludeDependencies += "org.log4j" % "log4j" // 不知道为什么但是 activator 阶段在编译时开始报错 // http://stackoverflow.com/questions/22974766/play2-play-stage-command-fails-with-not-found-type-setupcontext 编译中的文档中的来源:= List()

我尝试按照this thread in Github添加crossPaths := false

自从我在Missing Implementations 上看到该消息后,我已将此消息添加到我的build.sbt(通过各种谷歌搜索):

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

但没有运气。整个上午我都在各种 Stackoverflow 线程和 github 问题thisthisthis

如果有人对我如何调试这种情况有一些想法。

【问题讨论】:

    标签: unit-testing playframework sbt


    【解决方案1】:

    在我的情况下,这有效:

    打开 sbt 控制台:sbt

    运行测试:testOnly *test *

    所以添加* 解决了这个问题。

    【讨论】:

    • 感谢您的参与。但不幸的是,它没有奏效。 test * 无法被 sbt 识别 testOnly * 已执行,但未运行任何测试
    • 您是否尝试过testOnly *Test* 或其他与测试名称匹配的内容?
    • 我试过testOnly *testOnly com.package.*testOnly com.*testOnly com.package.ClassWithJunitTest*
    【解决方案2】:

    如果您正在运行 JUnit 测试,请将以下内容添加到 build.sbt:

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

    JUnit 测试可能确实在运行,但日志事件处于DEBUG 级别,因此您看不到它们。根据docs-v 选项将它们记录在INFO 级别:

    记录“测试运行开始”/“测试开始”/“测试运行完成”事件 在日志级别“信息”而不是“调试”。

    在我的机器上设置 -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 测试选项,则没有输出。

    【讨论】:

    • 感谢您的参与,没有太多解释,事情又开始工作了(我做了 clean、cleanFiles、compile、stage),并且混合起来,事情开始工作了(不需要尝试你的解决方案)。但我赞成它,因为我将来可能需要它。
    猜你喜欢
    • 1970-01-01
    • 2018-10-08
    • 1970-01-01
    • 2017-08-25
    • 2011-06-06
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 2018-06-08
    相关资源
    最近更新 更多