1

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)
  }
}
Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
jilen
  • 5,633
  • 3
  • 35
  • 84

3 Answers3

4

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!

Rodney Gitzel
  • 2,652
  • 16
  • 23
  • That's not always the problem, alas. – Rodney Gitzel Jul 07 '12 at 00:34
  • Thanks! Too bad eclipse doesn't warn when a source file's package declaration varies from the dir it lives in... (just because a file appears in the package explorer under a given package doesn't actually mean the package declaration matches!) – pretzels1337 Apr 03 '14 at 21:33
1

This is a known problem with the Eclipse IDE for Scala. I'm currently working on the plugin for this. Watch this space.

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
  • the new beta5 release solved this problem. But have problem while multi unit tests in single source file – jilen Jun 30 '11 at 03:30
0

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.

Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272