片段评估错误
有人可以告诉我“片段评估错误”是什么意思,或者我可以在哪里寻找解决方案?我有时(但并非总是)会遇到很多这样的错误(无需更改我的代码):
[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 模型伴随对象的第一行:
val test4 = Post.fixJValue(toextract4).extract[Selection]
我正在使用 Scala 2.9.0- 1.
另外:我不知道这是否重要,但 Post 是一个 net.liftweb.mongodb.record.MongoRecord 类伴随对象:
object Post extends Post with MongoMetaRecord[Post] { ... }
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)
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]
I'm using Scala 2.9.0-1.
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] { ... }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在specs2规范中,
Fragments
是规范的一部分。Fragment
可以是Text
、Example
、Step
。一些片段,例如
Example
和Step
是要执行的,并且应该捕获异常,以便将它们标记为失败。但它们不会捕获Error
(AssertionError
除外)。因此,如果示例抛出OutOfMemoryError
,这将被报告为片段评估错误。其他片段(例如
Text
片段)在评估时不应抛出异常。如果这样做,您将收到相同的片段评估错误
消息。如果没有看到完整的规范,我很难说出那里发生了什么,但我怀疑您在
Example
的主体中抛出了非异常类型。但我现在的问题多于答案:test4
在哪里声明?在规范主体内?在Context
案例类中?In a specs2 specification,
Fragments
are pieces of the specification. AFragment
can be aText
, anExample
, aStep
.Some fragments, like
Example
andStep
are meant to be executed and are supposed to catch Exceptions so that they can be marked as failures. But they won't catchError
s (exceptAssertionError
s). So if an Example throws anOutOfMemoryError
, this will be reported as a Fragment evaluation error.Other fragments, like
Text
fragments are not supposed to throw exceptions when being evaluated. If they do, you will get the sameFragment evaluation error
message.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
declared? Inside the specification body? Inside aContext
case class?