Setting up ScalaTest with Eclipse and JUnit4

415 views
Skip to first unread message

cessationoftime

unread,
Aug 27, 2011, 4:13:21 PM8/27/11
to scalatest-users
I am trying to get ScalaTest to work with Eclipse and JUnit4, but I
just can't get past an exception claiming my test class has "No
Runnable Methods". I get the impression that it is failing to use
org.scalatest.junit.JUnitRunner since that class does not appear in my
stacktrace. But i really have no idea why.


import org.scalatest.matchers.ShouldMatchers
import org.scalatest.WordSpec
import scala.collection.mutable.Stack
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class ActivityViewExerciseScalaTest extends WordSpec with
ShouldMatchers {
val test: String = "";
"A Stack" when {

"empty" should {

val stack = new Stack[Int]

"be empty" in {
stack should be ('empty)
}

"complain when popped" in {
evaluating { stack.pop() } should produce
[NoSuchElementException]
}
}
}

}

java.lang.Exception: No runnable methods
at
org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:
177)
at
org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:
122)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:269)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:66)
at
org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:
58)
at
org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:
13)
at
org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:
57)
at
org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:
29)
at
org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:
57)
at
org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:
24)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:
32)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:
25)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:
41)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:
31)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
452)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:
390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:
197)

Bill Venners

unread,
Aug 28, 2011, 4:28:39 PM8/28/11
to scalate...@googlegroups.com
I don't see anything wrong looking at the code, and you're right, from
the stack trace it looks like it is trying to use JUnit4's default
runner instead of the ScalaTest one. What versions of Eclipse, Scala,
JUnit, and ScalaTest are you using?

Has anyone else had this trouble with Eclipse?

Bill

> --
> You received this message because you are subscribed to the Google
> Groups "scalatest-users" group.
> To post to this group, send email to scalate...@googlegroups.com
> To unsubscribe from this group, send email to
> scalatest-use...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/scalatest-users?hl=en
> ScalaTest itself, and documentation, is available here:
> http://www.artima.com/scalatest
>

--
Bill Venners
Artima, Inc.
http://www.artima.com

cessationoftime

unread,
Aug 29, 2011, 8:03:15 PM8/29/11
to scalatest-users
It is working now, but I'm afraid I don't know what I did that made it
start working. I think it is something in my configuration rather
than the versions I am using.

However, I am using:
Eclipse Helios SR2
Scala-Lang 2.9.0 rather than 2.9.0-1 (for no good reason)
scalatest_2.9.0 version 1.6.1
JUnit 4.8.2


Now that it is working I intend to try to get it running with the
Robolectric for Android

Bill Venners

unread,
Aug 29, 2011, 9:20:06 PM8/29/11
to scalate...@googlegroups.com
Hi,

Good to hear it is working now. If you eventually figure out what did
the trick please go ahead and post it here for future reference.

Thanks.

Bill

Kieron Wilkinson

unread,
Aug 30, 2011, 11:17:11 AM8/30/11
to scalatest-users
Just for the record, the exact same thing just happened to me in
IntelliJ using the FSC compile server. I had my test, and later I
added the RunWith annotation (was running with ScalaTest before), but
JUnit just wouldn't discover it. I restarted IntelliJ and then it
started working, so I assume that in my case, it was because IntelliJ/
FSC didn't recompile my test for some reason.

Hopefully that helps if somebody else has the same problem.

Kieron
Reply all
Reply to author
Forward
0 new messages