specs2 - 如何在对集合的所有元素进行 Specs2 测试失败时获取有意义的消息?

标签 specs2

我有一个文件列表 exampleProblems,我想对每个文件应用一个方法并检查它是否不会抛出异常。问题是我没有从 Specs2 收到良好的失败消息。我需要找出导致问题的因素。我已经尝试添加 aka,但没有成功。

这是代码:

def is: Fragments =
    "parse all example uai files" ! (exampleProblems must contain((p: String) => {
      Problem.parseUAIProblem(ClassLoader.getSystemResourceAsStream(p)).aka(p) must throwAn[Exception].not
    }).forall)

这是我收到的消息:

java.lang.Exception: There is 1 failure Got the exception java.lang.IllegalArgumentException: requirement failed: variables are not ordered increasingly

at vultura.fastfactors.UAIParserTest$$anonfun$is$1$$anonfun$apply$1.apply(UAIParserTest.scala:24) at vultura.fastfactors.UAIParserTest$$anonfun$is$1$$anonfun$apply$1.apply(UAIParserTest.scala:24)

最佳答案

这意味着应该改进 throwA[E] 匹配器,以便在使用 aka 时显示预期的描述。我会解决这个问题,但作为解决方法,你可以写:

class TestSpec extends Specification {  def is =
  "parse all example uai files" ! {
    Seq("a", "b") must contain { (p: String) =>
      s"$p is ok" ==> { { sys.error("bang"); p} must not (throwAn[Exception]) }
    }.forall
  }
}

这显示:

[info] x parse all example uai files
[error]  There is 1 failure
[error]  a is not ok because Got the exception java.lang.RuntimeException: bang

关于specs2 - 如何在对集合的所有元素进行 Specs2 测试失败时获取有意义的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19360404/

相关文章:

scala - 在 Spec2 中的每个测试之前执行重置方法

scala - 找不到用于测试的现有数据 Scala Specs2

playframework-2.0 - 使用 Fakeapplication 的规范测试失败,无法访问 play.Cache -> 不存在应用程序

scala - 如何使用 SpecWithJUnit 将测试标记为 pendingUntilFixed

unit-testing - 如何减少specs2中的故障显示

database - 使用 scala play specs2 针对测试 mysql 数据库的演变

scala - 在没有匹配器的情况下如何跳过specs2中的测试?

specs2 - 为什么 ScalaCheck 在我的规范中丢弃这么多生成的值?

scala - 让测试仅在 SBT 控制台外工作

scala - 在specs2匹配器中组合forall和^^^