org.scalatest.junit

JUnit3Suite

class JUnit3Suite extends TestCase with Suite with AssertionsForJUnit

A Suite that is also a junit.framework.TestCase.

A JUnit3Suite may be run by either JUnit 3 (such as JUnit 3.8) or ScalaTest's runner. You write it the way you write a JUnit 3 TestCase. Tests are methods that start with test, take no parameters, and have a Unit return type. You manage fixtures with methods setUp and tearDown. Here's an example:

import org.scalatest.junit.JUnit3Suite
import scala.collection.mutable.ListBuffer

class BlastFromThePastSuite extends JUnit3Suite {

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

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

  def testEasy() { // Uses JUnit-style assertions
    sb.append("easy!")
    assertEquals("ScalaTest is easy!", sb.toString)
    assertTrue(lb.isEmpty)
    lb += "sweet"
  }

  def testFun() { // Uses ScalaTest assertions
    sb.append("fun!")
    assert(sb.toString === "ScalaTest is fun!")
    assert(lb.isEmpty)
  }
}

You can use either JUnit's assertions, inherited from TestCase, or ScalaTest's, inherited from AssertionsForJUnit. You can also mix in ShouldMatchersForJUnit or MustMatchersForJUnit if you want to use ScalaTests's matchers DSL. Here's an example:

import org.scalatest.junit.JUnit3Suite
import org.scalatest.junit.MustMatchersForJUnit
import scala.collection.mutable.ListBuffer

class BlastFromThePastSuite extends JUnit3Suite with MustMatchersForJUnit {

  var stringBuilder: StringBuilder = _
  var listBuffer: ListBuffer[String] = _

  override def setUp() {
    stringBuilder = new StringBuilder("ScalaTest is ")
    listBuffer = new ListBuffer[String]
  }

  def testEasy() {
    stringBuilder.append("easy!")
    stringBuilder.toString must be ("ScalaTest is easy!")
    listBuffer must be ('empty)
    listBuffer += "sweet"
  }

  def testFun() {
    stringBuilder.append("fun!")
    stringBuilder.toString must be ("ScalaTest is fun!")
    listBuffer must be ('empty)
  }
}

The reason you would ordinarily want to mix in MustMatchersForJUnit or ShouldMatchersForJUnit rather than MustMatchers or ShouldMatchers is that MustMatchersForJUnit and ShouldMatchersForJUnit throw junit.framework.AssertionFailedErrors, which JUnit 3 will report as failures, not errors.

When writing JUnit 3 tests in Scala, you should keep in mind that JUnit 3 will not run tests that have a return type other than Unit. Thus it is best to leave off the equals sign before the curly braces of the body of the test, like this:

def testGoodIdea() { // result type will be Unit
  // ...
}

Instead of this:

def testBadIdea() = { // result type will be inferred
  // ...
}

If the testBadIdea method ends in an expression that has a result type other than Unit, the Scala compiler will infer a result type to the testBadIdea method to be the same non-Unit type. As a "result," JUnit 3 will not discover or run the testBadIdea method at all.

Self Type
JUnit3Suite
Linear Supertypes
AssertionsForJUnit, Suite, Serializable, Serializable, Assertions, TripleEquals, TripleEqualsSupport, TestCase, Test, Assert, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. JUnit3Suite
  2. AssertionsForJUnit
  3. Suite
  4. Serializable
  5. Serializable
  6. Assertions
  7. TripleEquals
  8. TripleEqualsSupport
  9. TestCase
  10. Test
  11. Assert
  12. AnyRef
  13. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new JUnit3Suite()

Type Members

  1. class AssertionsHelper extends AnyRef

    Definition Classes
    Assertions
  2. class CheckingEqualizer[L] extends AnyRef

    Definition Classes
    TripleEqualsSupport
  3. class Equalizer[L] extends AnyRef

    Definition Classes
    TripleEqualsSupport
  4. trait NoArgTest extends () ⇒ Outcome with TestData

    Attributes
    protected
    Definition Classes
    Suite

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. def !==[T](right: Spread[T]): TripleEqualsInvocationOnSpread[T]

    Definition Classes
    TripleEqualsSupport
  4. def !==(right: Null): TripleEqualsInvocation[Null]

    Definition Classes
    TripleEqualsSupport
  5. def !==[T](right: T): TripleEqualsInvocation[T]

    Definition Classes
    TripleEqualsSupport
  6. final def ##(): Int

    Definition Classes
    AnyRef → Any
  7. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  8. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  9. def ===[T](right: Spread[T]): TripleEqualsInvocationOnSpread[T]

    Definition Classes
    TripleEqualsSupport
  10. def ===(right: Null): TripleEqualsInvocation[Null]

    Definition Classes
    TripleEqualsSupport
  11. def ===[T](right: T): TripleEqualsInvocation[T]

    Definition Classes
    TripleEqualsSupport
  12. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  13. def assert(condition: Boolean, clue: Any): Assertion

    Definition Classes
    Assertions
    Annotations
    @macroImpl( ... )
  14. def assert(condition: Boolean): Assertion

    Definition Classes
    Assertions
    Annotations
    @macroImpl( ... )
  15. def assertCompiles(code: String): Assertion

    Definition Classes
    Assertions
    Annotations
    @macroImpl( ... )
  16. def assertDoesNotCompile(code: String): Assertion

    Definition Classes
    Assertions
    Annotations
    @macroImpl( ... )
  17. def assertResult(expected: Any)(actual: Any): Assertion

    Definition Classes
    Assertions
  18. def assertResult(expected: Any, clue: Any)(actual: Any): Assertion

    Definition Classes
    Assertions
  19. def assertThrows[T <: AnyRef](f: ⇒ Any)(implicit classTag: ClassTag[T]): Assertion

    Definition Classes
    Assertions
  20. def assertTypeError(code: String): Assertion

    Definition Classes
    Assertions
    Annotations
    @macroImpl( ... )
  21. val assertionsHelper: AssertionsHelper

    Definition Classes
    Assertions
  22. def assume(condition: Boolean, clue: Any): Assertion

    Definition Classes
    Assertions
    Annotations
    @macroImpl( ... )
  23. def assume(condition: Boolean): Assertion

    Definition Classes
    Assertions
    Annotations
    @macroImpl( ... )
  24. def cancel(cause: Throwable): Nothing

    Definition Classes
    Assertions
  25. def cancel(message: String, cause: Throwable): Nothing

    Definition Classes
    Assertions
  26. def cancel(message: String): Nothing

    Definition Classes
    Assertions
  27. def cancel(): Nothing

    Definition Classes
    Assertions
  28. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. def conversionCheckedConstraint[A, B](implicit equivalenceOfA: Equivalence[A], cnv: (B) ⇒ A): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  30. def convertEquivalenceToAToBConstraint[A, B](equivalenceOfB: Equivalence[B])(implicit ev: <:<[A, B]): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  31. def convertEquivalenceToAToBConversionConstraint[A, B](equivalenceOfB: Equivalence[B])(implicit ev: (A) ⇒ B): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  32. def convertEquivalenceToBToAConstraint[A, B](equivalenceOfA: Equivalence[A])(implicit ev: <:<[B, A]): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  33. def convertEquivalenceToBToAConversionConstraint[A, B](equivalenceOfA: Equivalence[A])(implicit ev: (B) ⇒ A): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  34. def convertToCheckingEqualizer[T](left: T): CheckingEqualizer[T]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  35. implicit def convertToEqualizer[T](left: T): Equalizer[T]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  36. def countTestCases(): Int

    Definition Classes
    TestCase → Test
  37. def createResult(): TestResult

    Attributes
    protected[junit.framework]
    Definition Classes
    TestCase
  38. def defaultEquality[A]: Equality[A]

    Definition Classes
    TripleEqualsSupport
  39. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  40. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  41. final def execute: Unit

    Definition Classes
    Suite
  42. final def execute(testName: String, configMap: ConfigMap, color: Boolean, durations: Boolean, shortstacks: Boolean, fullstacks: Boolean, stats: Boolean): Unit

    Definition Classes
    Suite
  43. def expectedTestCount(filter: Filter): Int

    Returns the number of tests expected to be run by JUnit when run is invoked on this Suite.

    Returns the number of tests expected to be run by JUnit when run is invoked on this Suite.

    If tagsToInclude in the passed Filter is defined, this class's implementation of this method returns 0. Else this class's implementation of this method returns the size of the set returned by testNames on the current instance.

    Definition Classes
    JUnit3Suite → Suite
  44. def fail(cause: Throwable): Nothing

    Definition Classes
    Assertions
  45. def fail(message: String, cause: Throwable): Nothing

    Definition Classes
    Assertions
  46. def fail(message: String): Nothing

    Definition Classes
    Assertions
  47. def fail(): Nothing

    Definition Classes
    Assertions
  48. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  49. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  50. def getName(): String

    Definition Classes
    TestCase
  51. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  52. def intercept[T <: AnyRef](f: ⇒ Any)(implicit classTag: ClassTag[T]): T

    Definition Classes
    Assertions
  53. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  54. def lowPriorityConversionCheckedConstraint[A, B](implicit equivalenceOfB: Equivalence[B], cnv: (A) ⇒ B): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  55. def lowPriorityTypeCheckedConstraint[A, B](implicit equivalenceOfB: Equivalence[B], ev: <:<[A, B]): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  56. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  57. def nestedSuites: IndexedSeq[Suite]

    Definition Classes
    Suite
  58. final def notify(): Unit

    Definition Classes
    AnyRef
  59. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  60. def pending: Assertion with PendingStatement

    Definition Classes
    Assertions
  61. def pendingUntilFixed(f: ⇒ Unit): Assertion with PendingStatement

    Definition Classes
    Assertions
  62. def rerunner: Option[String]

    Definition Classes
    Suite
  63. def run(testName: Option[String], args: Args): Status

    Overrides to use JUnit 3 to run the test(s).

    Overrides to use JUnit 3 to run the test(s).

    testName

    an optional name of one test to run. If None, all relevant tests should be run. I.e., None acts like a wildcard that means run all relevant tests in this Suite.

    args

    the Args for this run

    returns

    a Status object that indicates when all tests and nested suites started by this method have completed, and whether or not a failure occurred.

    Definition Classes
    JUnit3Suite → Suite
  64. def run(arg0: TestResult): Unit

    Definition Classes
    TestCase → Test
  65. def run(): TestResult

    Definition Classes
    TestCase
  66. def runBare(): Unit

    Definition Classes
    TestCase
    Annotations
    @throws( classOf[java.lang.Throwable] )
  67. final def runNestedSuites(args: Args): Status

    Throws UnsupportedOperationException, because this method is unused by this class, given this class's run method delegates to JUnit to run its tests.

    Throws UnsupportedOperationException, because this method is unused by this class, given this class's run method delegates to JUnit to run its tests.

    The main purpose of this method implementation is to render a compiler error an attempt to mix in a trait that overrides runNestedSuites. Because this trait does not actually use runNestedSuites, the attempt to mix in behavior would very likely not work.

    args

    the Args for this run

    Attributes
    protected
    Definition Classes
    JUnit3Suite → Suite
    Exceptions thrown
    UnsupportedOperationException

    always.

  68. final def runTest(testName: String, args: Args): Status

    Throws UnsupportedOperationException, because this method is unused by this class, given this class's run method delegates to JUnit to run its tests.

    Throws UnsupportedOperationException, because this method is unused by this class, given this class's run method delegates to JUnit to run its tests.

    The main purpose of this method implementation is to render a compiler error an attempt to mix in a trait that overrides runTest. Because this trait does not actually use runTest, the attempt to mix in behavior would very likely not work.

    testName

    the name of one test to run.

    args

    the Args for this run

    Attributes
    protected
    Definition Classes
    JUnit3Suite → Suite
    Exceptions thrown
    UnsupportedOperationException

    always.

  69. def runTest(): Unit

    Attributes
    protected[junit.framework]
    Definition Classes
    TestCase
    Annotations
    @throws( classOf[java.lang.Throwable] )
  70. final def runTests(testName: Option[String], args: Args): Status

    Throws UnsupportedOperationException, because this method is unused by this class, given this class's run method delegates to JUnit to run its tests.

    Throws UnsupportedOperationException, because this method is unused by this class, given this class's run method delegates to JUnit to run its tests.

    The main purpose of this method implementation is to render a compiler error an attempt to mix in a trait that overrides runTests. Because this trait does not actually use runTests, the attempt to mix in behavior would very likely not work.

    testName

    an optional name of one test to run. If None, all relevant tests should be run. I.e., None acts like a wildcard that means run all relevant tests in this Suite.

    args

    the Args for this run

    Attributes
    protected
    Definition Classes
    JUnit3Suite → Suite
    Exceptions thrown
    UnsupportedOperationException

    always.

  71. def setName(arg0: String): Unit

    Definition Classes
    TestCase
  72. def setUp(): Unit

    Attributes
    protected[junit.framework]
    Definition Classes
    TestCase
    Annotations
    @throws( classOf[java.lang.Exception] )
  73. final val styleName: String

    Suite style name.

    Suite style name.

    returns

    JUnit3Suite

    Definition Classes
    JUnit3Suite → Suite
  74. final val succeed: Succeeded.type

    Definition Classes
    Assertions
  75. def suiteId: String

    Definition Classes
    Suite
  76. def suiteName: String

    Definition Classes
    Suite
  77. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  78. def tags: Map[String, Nothing]

    Returns an empty Map, because tags are not supported by JUnit 3.

    Returns an empty Map, because tags are not supported by JUnit 3.

    Definition Classes
    JUnit3Suite → Suite
  79. def tearDown(): Unit

    Attributes
    protected[junit.framework]
    Definition Classes
    TestCase
    Annotations
    @throws( classOf[java.lang.Exception] )
  80. final def testDataFor(testName: String, theConfigMap: ConfigMap = ConfigMap.empty): TestData

    Definition Classes
    JUnit3Suite → Suite
  81. def testNames: Set[String]

    Returns the set of test names that will be executed by JUnit when run is invoked on an instance of this class, or the instance is passed directly to JUnit for running.

    Returns the set of test names that will be executed by JUnit when run is invoked on an instance of this class, or the instance is passed directly to JUnit for running.

    The iterator obtained by invoking elements on this returned Set will produce the test names in their natural order, as determined by String's compareTo method. Nevertheless, this method is not consulted by JUnit when it runs the tests, and JUnit may run the tests in any order.

    Definition Classes
    JUnit3Suite → Suite
  82. def toString(): String

    Definition Classes
    TestCase → AnyRef → Any
  83. def trap[T](f: ⇒ T): Throwable

    Definition Classes
    Assertions
  84. def typeCheckedConstraint[A, B](implicit equivalenceOfA: Equivalence[A], ev: <:<[B, A]): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  85. implicit def unconstrainedEquality[A, B](implicit equalityOfA: Equality[A]): CanEqual[A, B]

    Definition Classes
    TripleEquals → TripleEqualsSupport
  86. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  87. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  88. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  89. def withClue[T](clue: Any)(fun: ⇒ T): T

    Definition Classes
    Assertions
  90. final def withFixture(test: NoArgTest): Outcome

    Throws UnsupportedOperationException, because this method is unused by this class, given this class's run method delegates to JUnit to run its tests.

    Throws UnsupportedOperationException, because this method is unused by this class, given this class's run method delegates to JUnit to run its tests.

    The main purpose of this method implementation is to render a compiler error an attempt to mix in a trait that overrides withFixture. Because this trait does not actually use withFixture, the attempt to mix in behavior would very likely not work.

    test

    the no-arg test function to run with a fixture

    Attributes
    protected
    Definition Classes
    JUnit3Suite → Suite

Inherited from AssertionsForJUnit

Inherited from Suite

Inherited from Serializable

Inherited from Serializable

Inherited from Assertions

Inherited from TripleEquals

Inherited from TripleEqualsSupport

Inherited from TestCase

Inherited from Test

Inherited from Assert

Inherited from AnyRef

Inherited from Any

Ungrouped