片段评估错误 [英] Fragment Evaluation Error
问题描述
有人可以告诉我片段评估错误"是什么意思,或者我可能在哪里寻找解决方案?有时候(但并非总是)(在不更改代码的情况下)会出现很多这样的错误:
Can someone tell me what "Fragment evaluation error" means, or where I might look for solutions? I sometimes (but not always) get lots of these errors (without changing my code):
[error] ! Fragment evaluation error
[error] ThrowableException: Could not initialize class code.model.Post$ (FutureTask.java:138)
[error] code.model.PostSpec$$anonfun$1$$anonfun$apply$1.apply$mcZ$sp(PostSpec.scala:68)
[error] code.model.PostSpec$$anonfun$1$$anonfun$apply$1.apply(PostSpec.scala:51)
[error] code.model.PostSpec$$anonfun$1$$anonfun$apply$1.apply(PostSpec.scala:51)
PostSpec的第68行是(specs2)测试中引用Post模型随播对象的第一行:
Line 68 of PostSpec is the first line in the (specs2) test that references the Post model companion object:
val test4 = Post.fixJValue(toextract4).extract[Selection]
我正在使用Scala 2.9.0-1.
I'm using Scala 2.9.0-1.
也:我不知道这是否重要,但Post是一个net.liftweb.mongodb.record.MongoRecord类随行对象:
Also: I have no idea whether it matters, but Post is a net.liftweb.mongodb.record.MongoRecord class companion object:
object Post extends Post with MongoMetaRecord[Post] { ... }
推荐答案
在specs2规范中,Fragments
是该规范的一部分. Fragment
可以是Text
,Example
,Step
.
In a specs2 specification, Fragments
are pieces of the specification. A Fragment
can be a Text
, an Example
, a Step
.
某些片段(例如Example
和Step
)应被执行,并应捕获异常,以便可以将它们标记为失败.但是它们不会捕获Error
(AssertionError
除外).因此,如果示例抛出OutOfMemoryError
,则将其报告为片段评估错误.
Some fragments, like Example
and Step
are meant to be executed and are supposed to catch Exceptions so that they can be marked as failures. But they won't catch Error
s (except AssertionError
s). So if an Example throws an OutOfMemoryError
, this will be reported as a Fragment evaluation error.
其他片段(例如Text
片段)在被求值时不应引发异常.如果这样做,您将收到相同的Fragment evaluation error
消息.
Other fragments, like Text
fragments are not supposed to throw exceptions when being evaluated. If they do, you will get the same Fragment evaluation error
message.
在没有看到完整规范的情况下,我很难说出那里发生了什么,但是我怀疑您在Example
的正文中抛出了非Exception类型.但是我现在有很多问题要比答案多了:
Without seeing the full specification it's hard for me to say what's happening there but I suspect that you had a non-Exception type thrown in the body of an Example
. But I have more questions than answers for now:
-
test4
在哪里声明?在规范体内?在Context
案例类中? - 由于错误是间歇性发生的,因此您确定始终具有正确的mongodb上下文吗?也许您的规范示例正在同一mongo数据库实例上同时执行?
- where is
test4
declared? Inside the specification body? Inside aContext
case class? - since errors happen intermittently, are you sure you always have a proper mongodb context? Maybe your specification examples are being executed concurrently on the same mongo db instance?
这篇关于片段评估错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!