我有一个文件列表 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/