I've spent the past few days trying to find a combination of unit tests that work with scala for my project and this is what I've found.
I am using the release candidates for Scala 2.8 because it fixes a number of bugs that were blocking me in 2.7.2. I initially tried to get Scalatest to work with 2.8, but was unable to find a stable solution, in the future that may be a better way to go, but currently there appears to be too much in flux around the 2.8 release.
The configuration I have working is to use JUnit4 annotations in my scala test code like so:
import org.junit._
import Assert._
class TestSuite{
@Test def testSimple(){
asserEquals("Equal",1,1)
}
}
Then I am using a java JUnit test suite to run all my tests together like so:
import junit.framework.Test;
import junit.framework.TestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses( {
TestSuite.class
})
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test Suite");
return suite;
}
}
The only additional trick is to add the output directory as a source directory in Eclipse so that the JUnit runner can find your class files. This is a bit of a hack, but it seems to work.
Project->Properties->Java Build Path->Source->Add Folder and then click on classes (or bin, wherever you are compiling your class files to).
This runs fine in Eclipse by right clicking on AllTests.java and selecting RunAs->Junit