eclipse不会将最新的flatspec视为junit测试

时间:2011-04-17 10:46:06

标签: eclipse scala scalatest scala-ide

这是我的测试用例,而我右键单击文件eclipse doest不显示任何运行为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)
  }
}

3 个答案:

答案 0 :(得分:4)

我似乎随机地遇到了这个,我想我终于找到了原因。

不幸的是,插件在移动文件时还没有更改包声明,在重命名文件时也没有更改类名。 (假设您可以将多个类放在一个文件中,后者可能永远不会完成。)如果您习惯于在Eclipse中自动完成重命名,就像我一样,您一定会被抓住这个。

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

  1. Scala文件中的包声明与Eclipse包名称匹配
  2. Scala文件中 in 的测试类的名称与Scala文件的名称相匹配
  3. 我刚碰到这个,修复了两个,现在我的测试运行了!

答案 1 :(得分:1)

这是Eclipse IDE for Scala的一个已知问题。我目前正在为这个插件工作。看这个空间。

答案 2 :(得分:0)

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