【问题标题】:How to configure sbt test / ScalaTest to only show failures?如何配置 sbt test / ScalaTest 只显示失败?
【发布时间】:2014-03-15 09:43:19
【问题描述】:

有没有办法截断测试结果,仅在单元测试失败时才显示单元测试的结果文本?我正在开发一个包含 850 个单元测试的 Scala 项目,成功的单元测试中的绿色文本让人很难只关注失败。

我所说的例子:

[info] - should have colors
[info] - should not be dead
//.... x 100
[info] - animals should not be rainbows *** FAILED *** 
[info] -"[rainbow]s" was not equal to "[ponie]s" (HappinessSpec.scala:31)

我想要的只是显示失败的东西:

[info] - animals should not be rainbows *** FAILED *** 
[info] -"[rainbow]s" was not equal to "[ponie]s" (HappinessSpec.scala:31)

我意识到有test-quick sbt 命令,但它仍在运行 300 成功 在我的案例中,只有 30 次失败时的单元测试。

在使用方面与此类似的东西是我正在寻找的:

sbt> ~ test -showOnlyFailures

如果在运行结束时显示所有失败,我也会很高兴 单元测试。 IIRC,这就是 RSpec 在 Ruby 中的工作方式...

【问题讨论】:

    标签: scala sbt scalatest


    【解决方案1】:

    在 build.sbt 中添加以下内容后,scalaTest 将在标准报告后显示失败摘要:

    testOptions in Test += Tests.Argument("-oI") 
    
    I - show reminder of failed and canceled tests without stack traces
    T - show reminder of failed and canceled tests with short stack traces
    G - show reminder of failed and canceled tests with full stack traces
    

    还有一个“drop TestSucceeded events”标志,但我没有使用它: http://www.scalatest.org/user_guide/using_the_runner

    【讨论】:

    • 你是否碰巧有一个小型的 sbt 框架项目来显示这个工作?我在 Scala 2.10 中使用 ScalaTest 1.9.1 进行了尝试,它似乎只适用于 these 配置选项,而使用 ScalaTest 2.0,我得到奇怪的 ScalaTest 异常,并且所有配置选项似乎都不起作用。
    • 是的,它似乎只适用于 ScalaTest 2.0。 bitbucket.org/goozez/scalatest-failskeleton
    • 我们使用maven。我们运气不好?
    【解决方案2】:

    对于使用 maven 和 scalatest-maven-plugin 的用户,您可以添加此配置:

    <configuration>
      <stdout>I</stdout>
    </configuration>
    

    【讨论】:

      【解决方案3】:

      你可以试试 sbt 命令

      last-grep error test

      这应该只显示错误/失败。

      【讨论】:

        【解决方案4】:

        Scalatest 3 的更新答案。

        这是 build.sbt 文件的新语法,用于在测试套件运行的底部重新打印所有失败:

        testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-oI")
        

        您可能还想隐藏信息通知,以便更容易看到失败。

        testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-oNCXELOPQRM")
        

        以下是所有选项的含义:

        • N - 删除 TestStarting 事件
        • C - 删除 TestSucceeded 事件
        • X - 删除 TestIgnored 事件
        • E - 删除 TestPending 事件
        • H - 删除 SuiteStarting 事件
        • L - 删除 SuiteCompleted 事件
        • O - 删除 InfoProvided 事件
        • P - 删除 ScopeOpened 事件
        • Q - 删除 ScopeClosed 事件
        • R - 删除 ScopePending 事件
        • M - 删除 MarkupProvided 事件

        "-oI" 在测试套件运行结束时再次打印错误通知,而"-oNCXELOPQRM" 仅显示失败的测试。

        更多详情请参阅the configuring reporters section on the ScalaTest website。

        【讨论】:

        • 这个答案是完全正确的(它只打印失败),但我个人也希望看到挂起和忽略的测试,所以我删除了 X 和 E。
        猜你喜欢
        • 1970-01-01
        • 2011-09-21
        • 2015-07-30
        • 2014-11-18
        • 2016-10-29
        • 2015-01-17
        • 2018-06-04
        • 2013-08-06
        • 1970-01-01
        相关资源
        最近更新 更多