eclipse 不会将 scalatest flatspec 视为 junit 测试
这是我的测试用例,当我右键单击该文件时,Eclipse 没有显示任何 run as junit 测试选项。我尝试手动创建运行配置,但没有任何意义。 scala版本:2.8.1 scalatest:1.3 eclipse:3.6.2
package org.jilen.cache.segment
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
@RunWith(classOf[JUnitRunner])
class RandomSegmentSpec extends FlatSpec with ShouldMatchers {
val option = SegmentOptions()
"A Simple Segment" should "contains (douglas,lea) after put into" in {
val segment = RandomSegment.newSegment(option)
segment.put("douglas", "lea")
segment("douglas") should be("lea")
}
it should "return null after (douglas,lea) is remove" in {
val segment = RandomSegment.newSegment(option)
segment.put("douglas", "lea")
segment -= ("douglas")
segment("douglas") should equal(null)
}
it should "contains nothing after clear" in {
val segment = RandomSegment.newSegment(option)
segment.put("jilen", "zhang")
segment.put(10, "ten")
segment += ("douglas" -> "lea")
segment += ("20" -> 20)
segment.clear()
segment.isEmpty should be(true)
}
}
here is my test case , while i right click the file eclipse doest not show any run as junit test option. I try to manual create run configuration but does not take any sense.
scala version:2.8.1 scalatest:1.3 eclipse:3.6.2
package org.jilen.cache.segment
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
@RunWith(classOf[JUnitRunner])
class RandomSegmentSpec extends FlatSpec with ShouldMatchers {
val option = SegmentOptions()
"A Simple Segment" should "contains (douglas,lea) after put into" in {
val segment = RandomSegment.newSegment(option)
segment.put("douglas", "lea")
segment("douglas") should be("lea")
}
it should "return null after (douglas,lea) is remove" in {
val segment = RandomSegment.newSegment(option)
segment.put("douglas", "lea")
segment -= ("douglas")
segment("douglas") should equal(null)
}
it should "contains nothing after clear" in {
val segment = RandomSegment.newSegment(option)
segment.put("jilen", "zhang")
segment.put(10, "ten")
segment += ("douglas" -> "lea")
segment += ("20" -> 20)
segment.clear()
segment.isEmpty should be(true)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我似乎偶然遇到了这个问题,我想我终于明白了原因。
不幸的是,当您移动文件时,该插件尚未更改包声明,也不会在您重命名文件时更改类名。 (假设您可以将多个类放入一个文件中,则后者可能永远不会完成。)如果您像我一样习惯在 Eclipse 中自动完成重命名,那么您一定会陷入困境。
所以...仔细检查以下内容:
我刚刚遇到的 Scala 文件的名称匹配,修复了两者,现在我的测试运行了!
I've encountered this seemingly randomly, and I think I've finally figured out why.
Unfortunately the plugin doesn't yet change package declarations when you move files, nor the class names when you rename files. (Given you can put multiple classes in one file, the latter will likely never be done.) If you are used to the renamings being done automagically in Eclipse, like I am, you're bound to get caught on this.
So... check carefully the following:
I just ran into this, fixed both, and now my test runs!
这是 Scala 的 Eclipse IDE 的一个已知问题。我目前正在为此开发插件。留意这个空间。
This is a known problem with the Eclipse IDE for Scala. I'm currently working on the plugin for this. Watch this space.
我发现 Scalatest 在与 Eclipse 集成方面非常糟糕(从 Eclipse 运行测试表明它运行了它们 - 但它们不会通过或失败,而只是显示为被动的空白框)。
由于某种原因,我在尝试了 3 个小时后无法让它工作!
最后我尝试了 specs2 - 它起作用了(Scala 2.9、Junit4 和 Eclipse 3.6)!
他们这里有一位很棒的医生:
http://etorreborre.github.com/specs2 /guide/org.specs2.guide.Runners.html#Runners+guide
由于我不在乎使用哪个测试框架,所以我会尝试 Specs2 纯粹是从方便的角度来看。
I found Scalatest to be very bad at integrating with Eclipse (running the tests from eclipse showed that it ran them - but they would not pass or fail, but simply show up as passive blank boxes).
For some reason I could NOT get it to work after 3 hours of trying things!
Finally I tried specs2 - and it worked (Scala 2.9, Junit4 and Eclipse 3.6)!
They have a great doc here:
http://etorreborre.github.com/specs2/guide/org.specs2.guide.Runners.html#Runners+guide
Since I don't care which testing framework to use, I will try Specs2 purely from the convenience point of view.