eclipse 不会将 scalatest flatspec 视为 junit 测试

发布于 2024-11-01 20:55:32 字数 1169 浏览 7 评论 0原文

这是我的测试用例,当我右键单击该文件时,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清醇 2024-11-08 20:55:32

我似乎偶然遇到了这个问题,我想我终于明白了原因。

不幸的是,当您移动文件时,该插件尚未更改包声明,也不会在您重命名文件时更改类名。 (假设您可以将多个类放入一个文件中,则后者可能永远不会完成。)如果您像我一样习惯在 Eclipse 中自动完成重命名,那么您一定会陷入困境。

所以...仔细检查以下内容:

  1. Scala 文件中的包声明与 Eclipse 包名称匹配 Scala 文件
  2. 中的测试类名称与

我刚刚遇到的 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:

  1. the package declaration in your Scala file matches the Eclipse package name
  2. the name of the test class in the Scala file matches the name of the Scala file

I just ran into this, fixed both, and now my test runs!

掀纱窥君容 2024-11-08 20:55:32

这是 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.

初与友歌 2024-11-08 20:55:32

我发现 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文