Scala works fine with the JUnit testing framework. You simply use the Java interfaces and classes, just as if you were writing the tests in Java.

As an example, here is an individual test case that works with JUnit 3.8. Note that you can import all of the Assert.* methods for convenience:

package junitex
import junit.framework._
import Assert._
  
class TestList extends TestCase {
  def testLength = {
    assertTrue(List(1,2,3).length == 3)
    assertTrue(Nil.length == 0)
  }
}

Here is one way to assemble tests into a test suite:

package junitex
import junit.framework._

object Tests {
  def suite: Test = {
    val suite = new TestSuite
    suite.addTestSuite(classOf[TestList])
    // add more test classes as desired
    suite
  }
  def main(args : Array[String]) {
    junit.textui.TestRunner.run(suite);
  }
}
 
code/junit-tests.txt · Last modified: 2007/07/26 05:47 by stevej
 
Recent changes RSS feed Valid XHTML 1.0 Driven by DokuWiki