This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Running unit tests?

4 replies
Barry Kaplan
Joined: 2009-04-01,
User offline. Last seen 42 years 45 weeks ago.

In discussion with Miles on a trac issue, he mentioned that running scala
unit tests should work similar as it does with java. Should this be the case
with ScalaTest as well?

Given this test:

import org.scalatest.junit.JUnit3Suite

class ScalaTestTest extends JUnit3Suite {

def test() {
11 === 11
}
}

I get the following error:

junit.framework.AssertionFailedError: Exception in constructor: test
(java.lang.AbstractMethodError:
com.tm.ScalaTest.org$scalatest$Suite$$TestMethodPrefix_$eq(Ljava/lang/String;)V
at org.scalatest.Suite$class.$init$(Suite.scala:950)
at com.tm.ScalaTest.(ScalaTests.scala:5)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at junit.framework.TestSuite.createTest(TestSuite.java:61)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:283)
at junit.framework.TestSuite.(TestSuite.java:146)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59)
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)
)
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.TestSuite$1.runTest(TestSuite.java:97)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
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)

Is there some special configuration that must be perofrmed?

Barry Kaplan
Joined: 2009-04-01,
User offline. Last seen 42 years 45 weeks ago.
Re: Running unit tests?

I do see that the following test runs as expected:

import org.junit.Test
import org.junit.Assert

class Junit4TestTest {
@Test def one() {
assert(10 == 10)
}
}

But I have to manually create the run configuration. Has anybody gotten
eclipse to recognize a scala junit tests via the context menu? (BTW, the
"run as tests" context menu works on the package and finds this test.)

milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: Re: Running unit tests?

On Wed, May 6, 2009 at 10:21 PM, Barry Kaplan wrote:
>
> I do see that the following test runs as expected:
>
> import org.junit.Test
> import org.junit.Assert
>
> class Junit4TestTest {
>  @Test def one() {
>    assert(10 == 10)
>  }
> }
>
> But I have to manually create the run configuration. Has anybody gotten
> eclipse to recognize a scala junit tests via the context menu? (BTW, the
> "run as tests" context menu works on the package and finds this test.)

I'm able to right click in the package explorer and run as a unit test ...

Cheers,

Miles

Barry Kaplan
Joined: 2009-04-01,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Running unit tests?

Miles what eclipse are you running? I'm using M6 against the plugin nightly.
I definitely do not get the context menu item.

Bill Venners
Joined: 2008-12-18,
User offline. Last seen 31 weeks 5 days ago.
Re: Running unit tests?

Hi Barry,

Sorry I've heard of this problem before, but haven't had time to try
it myself. I'd like to try it myself to figure out what the abstract
method error is coming from. Probably a mismatch of Scala compiler
versions. Could you let me know what set up I need to reproduce this
problem? What version of Eclipse, Scala Eclipse plug in, ScalaTest,
Scala, etc.

Thanks.

Bill

On Wed, May 6, 2009 at 2:14 PM, Barry Kaplan wrote:
>
> In discussion with Miles on a trac issue, he mentioned that running scala
> unit tests should work similar as it does with java. Should this be the case
> with ScalaTest as well?
>
> Given this test:
>
> import org.scalatest.junit.JUnit3Suite
>
> class ScalaTestTest extends JUnit3Suite {
>
>  def test() {
>    11 === 11
>  }
> }
>
> I get the following error:
>
> junit.framework.AssertionFailedError: Exception in constructor: test
> (java.lang.AbstractMethodError:
> com.tm.ScalaTest.org$scalatest$Suite$$TestMethodPrefix_$eq(Ljava/lang/String;)V
>        at org.scalatest.Suite$class.$init$(Suite.scala:950)
>        at com.tm.ScalaTest.(ScalaTests.scala:5)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
> Source)
>        at java.lang.reflect.Constructor.newInstance(Unknown Source)
>        at junit.framework.TestSuite.createTest(TestSuite.java:61)
>        at junit.framework.TestSuite.addTestMethod(TestSuite.java:283)
>        at junit.framework.TestSuite.(TestSuite.java:146)
>        at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102)
>        at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59)
>        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)
> )
>        at junit.framework.Assert.fail(Assert.java:47)
>        at junit.framework.TestSuite$1.runTest(TestSuite.java:97)
>        at junit.framework.TestCase.runBare(TestCase.java:134)
>        at junit.framework.TestResult$1.protect(TestResult.java:110)
>        at junit.framework.TestResult.runProtected(TestResult.java:128)
>        at junit.framework.TestResult.run(TestResult.java:113)
>        at junit.framework.TestCase.run(TestCase.java:124)
>        at junit.framework.TestSuite.runTest(TestSuite.java:232)
>        at junit.framework.TestSuite.run(TestSuite.java:227)
>        at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
>        at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>        at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>        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)
>
> Is there some special configuration that must be perofrmed?
> --
> View this message in context: http://www.nabble.com/Running-unit-tests--tp23415651p23415651.html
> Sent from the Scala - Tools mailing list archive at Nabble.com.
>
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland