ScalaTest 1.1

This document is the API specification for ScalaTest 1.1

Class Summary
trait AssertionsForJUnit extends Assertions
Trait that contains ScalaTest's basic assertion methods, suitable for use with JUnit.
class JUnit3Suite extends junit.framework.TestCase with Suite with AssertionsForJUnit
A Suite that is also a junit.framework.TestCase.
final class JUnitRunner (suiteClass : java.lang.Class[Suite]) extends org.junit.runner.Runner with AnyRef
A JUnit Runner that knows how to run any ScalaTest Suite (or Spec, which extends Suite). This enables you to provide a JUnit RunWith annotation on any ScalaTest Suite. Here's an example:
 import org.junit.runner.RunWith
 import org.scalatest.junit.JUnitRunner
 import org.scalatest.FunSuite

 @RunWith(classOf[JUnitRunner])
 class MySuite extends FunSuite {
   // ...
 }
 
trait JUnitSuite extends Suite with AssertionsForJUnit
A suite of tests that can be run with either JUnit or ScalaTest. This trait allows you to write JUnit 4 tests with ScalaTest's more concise assertion syntax as well as JUnit's assertions (assertEquals, etc.). You create tests by defining methods that are annotated with Test, and can create fixtures with methods annotated with Before and After. For example:
 import org.scalatest.junit.JUnitSuite
 import scala.collection.mutable.ListBuffer
 import _root_.org.junit.Test
 import _root_.org.junit.Before

 class TwoSuite extends JUnitSuite {

   var sb: StringBuilder = _
   var lb: ListBuffer[String] = _

   @Before override def initialize() {
     sb = new StringBuilder("ScalaTest is ")
     lb = new ListBuffer[String]
   }

   @Test def verifyEasy() {
     sb.append("easy!")
     assert(sb.toString === "ScalaTest is easy!")
     assert(lb.isEmpty)
     lb += "sweet"
   }

   @Test def verifyFun() {
     sb.append("fun!")
     assert(sb.toString === "ScalaTest is fun!")
     assert(lb.isEmpty)
   }
 }
 
class JUnitTestFailedError (val message : scala.Option[java.lang.String], val cause : scala.Option[java.lang.Throwable], val failedCodeStackDepth : Int) extends junit.framework.AssertionFailedError with StackDepth
Exception that indicates a test failed.
class JUnitWrapperSuite (junitClassName : java.lang.String, loader : java.lang.ClassLoader) extends Suite
trait MustMatchersForJUnit extends MustMatchers with AssertionsForJUnit
Trait that makes ScalaTest's MustMatchers DSL syntax available for use with JUnit.
trait ShouldMatchersForJUnit extends ShouldMatchers with AssertionsForJUnit
Trait that makes ScalaTest's ShouldMatchers DSL syntax available for use with JUnit.
Object Summary
object AssertionsForJUnit extends AssertionsForJUnit
Companion object that facilitates the importing of AssertionsForJUnit members as an alternative to mixing it in. One use case is to import AssertionsForJUnit members so you can use them in the Scala interpreter:
 $ scala -cp junit3.8.2/junit.jar:../target/jar_contents 
 Welcome to Scala version 2.7.5.final (Java HotSpot(TM) Client VM, Java 1.5.0_16).
 Type in expressions to have them evaluated.
 Type :help for more information.

 scala> import org.scalatest.junit.AssertionsForJUnit._
 import org.scalatest.junit.AssertionsForJUnit._

 scala> assert(1 === 2)
 junit.framework.AssertionFailedError: 1 did not equal 2
 	at org.scalatest.junit.AssertionsForJUnit$class.assert(AssertionsForJUnit.scala:353)
 	at org.scalatest.junit.AssertionsForJUnit$.assert(AssertionsForJUnit.scala:672)
 	at .(:7)
 	at .()
 	at RequestResult$.(:3)
 	at RequestResult$.()
 	at RequestResult$result( expect(3) { 1 + 3 }
 junit.framework.AssertionFailedError: Expected 3, but got 4
 	at org.scalatest.junit.AssertionsForJUnit$class.expect(AssertionsForJUnit.scala:563)
 	at org.scalatest.junit.AssertionsForJUnit$.expect(AssertionsForJUnit.scala:672)
 	at .(:7)
 	at .()
 	at RequestResult$.(:3)
 	at RequestResult$.()
 	at RequestResult$result( val caught = intercept[StringIndexOutOfBoundsException] { "hi".charAt(-1) }
 caught: StringIndexOutOfBoundsException = java.lang.StringIndexOutOfBoundsException: String index out of range: -1
 
object MustMatchersForJUnit extends MustMatchersForJUnit
Companion object that facilitates the importing of MustMatchersForJUnit members as an alternative to mixing it in. One use case is to import MustMatchersForJUnit members so you can use them in the Scala interpreter:
 Macintosh-65:delus bv$ scala -cp .:../target/jar_contents:junit3.8.2/junit.jar
 Welcome to Scala version 2.7.5.final (Java HotSpot(TM) Client VM, Java 1.5.0_16).
 Type in expressions to have them evaluated.
 Type :help for more information.
 
 scala> import org.scalatest.junit.MustMatchersForJUnit._
 import org.scalatest.junit.MustMatchersForJUnit._
 
 scala> "hi" must have length (3)
 junit.framework.AssertionFailedError: "hi" did not have length 3
 	at org.scalatest.junit.MustMatchersForJUnit$class.newTestFailedException(MustMatchersForJUnit.scala:22)
 	at org.scalatest.junit.MustMatchersForJUnit$.newTestFailedException(MustMatchersForJUnit.scala:63)
 	at org.scalatest.matchers.Matchers$ResultOfHaveWordForString.length(Matchers.scala:4102)
 	at .( 1 must equal (2)
 junit.framework.AssertionFailedError: 1 did not equal 2
 	at org.scalatest.junit.MustMatchersForJUnit$class.newTestFailedException(MustMatchersForJUnit.scala:22)
 	at org.scalatest.junit.MustMatchersForJUnit$.newTestFailedException(MustMatchersForJUnit.scala:63)
 	at org.scalatest.matchers.MustMatchers$MustMethodHelper$.mustMatcher(MustMatchers.scala:800)
 	at org.scal...
 scala> "hello, world" must startWith ("hello")
 
 scala> 7 must (be >= (3) and not be <= (7))
 junit.framework.AssertionFailedError: 7 was greater than or equal to 3, but 7 was less than or equal to 7
 	at org.scalatest.junit.MustMatchersForJUnit$class.newTestFailedException(MustMatchersForJUnit.scala:22)
 	at org.scalatest.junit.MustMatchersForJUnit$.newTestFailedException(MustMatchersForJUnit.scala:63)
 	at org.scalatest.matchers.MustMatchers$MustMethodHelper$.sh...
 
object ShouldMatchersForJUnit extends ShouldMatchersForJUnit
Companion object that facilitates the importing of ShouldMatchersForJUnit members as an alternative to mixing it in. One use case is to import ShouldMatchersForJUnit members so you can use them in the Scala interpreter:
 Macintosh-65:delus bv$ scala -cp .:../target/jar_contents:junit3.8.2/junit.jar
 Welcome to Scala version 2.7.5.final (Java HotSpot(TM) Client VM, Java 1.5.0_16).
 Type in expressions to have them evaluated.
 Type :help for more information.
 
 scala> import org.scalatest.junit.ShouldMatchersForJUnit._
 import org.scalatest.junit.ShouldMatchersForJUnit._
 
 scala> "hi" should have length (3)
 junit.framework.AssertionFailedError: "hi" did not have length 3
 	at org.scalatest.junit.ShouldMatchersForJUnit$class.newTestFailedException(ShouldMatchersForJUnit.scala:22)
 	at org.scalatest.junit.ShouldMatchersForJUnit$.newTestFailedException(ShouldMatchersForJUnit.scala:63)
 	at org.scalatest.matchers.Matchers$ResultOfHaveWordForString.length(Matchers.scala:4102)
 	at .( 1 should equal (2)
 junit.framework.AssertionFailedError: 1 did not equal 2
 	at org.scalatest.junit.ShouldMatchersForJUnit$class.newTestFailedException(ShouldMatchersForJUnit.scala:22)
 	at org.scalatest.junit.ShouldMatchersForJUnit$.newTestFailedException(ShouldMatchersForJUnit.scala:63)
 	at org.scalatest.matchers.ShouldMatchers$ShouldMethodHelper$.shouldMatcher(ShouldMatchers.scala:800)
 	at org.scal...
 scala> "hello, world" should startWith ("hello")
 
 scala> 7 should (be >= (3) and not be <= (7))
 junit.framework.AssertionFailedError: 7 was greater than or equal to 3, but 7 was less than or equal to 7
 	at org.scalatest.junit.ShouldMatchersForJUnit$class.newTestFailedException(ShouldMatchersForJUnit.scala:22)
 	at org.scalatest.junit.ShouldMatchersForJUnit$.newTestFailedException(ShouldMatchersForJUnit.scala:63)
 	at org.scalatest.matchers.ShouldMatchers$ShouldMethodHelper$.sh...