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.
Overrides to use JUnit 3 to run the test(s).
Overrides to use JUnit 3 to run the test(s).
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.
the Args for this run
a Status object that indicates when all tests and nested suites started by this method have completed, and whether or not a failure occurred.
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.
the Args for this run
always.
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.
the name of one test to run.
the Args for this run
always.
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.
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.
the Args for this run
always.
Suite style name.
Returns an empty Map, because tags are not supported by JUnit 3.
Returns an empty Map, because tags are not supported by JUnit 3.
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.
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.
the no-arg test function to run with a fixture
A
Suitethat is also ajunit.framework.TestCase.A
JUnit3Suitemay be run by either JUnit 3 (such as JUnit 3.8) or ScalaTest's runner. You write it the way you write a JUnit 3TestCase. Tests are methods that start withtest, take no parameters, and have aUnitreturn type. You manage fixtures with methodssetUpandtearDown. 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 fromAssertionsForJUnit. You can also mix inShouldMatchersForJUnitorMustMatchersForJUnitif 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
MustMatchersForJUnitorShouldMatchersForJUnitrather thanMustMatchersorShouldMatchersis thatMustMatchersForJUnitandShouldMatchersForJUnitthrowjunit.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
testBadIdeamethod ends in an expression that has a result type other thanUnit, the Scala compiler will infer a result type to thetestBadIdeamethod to be the same non-Unittype. As a "result," JUnit 3 will not discover or run thetestBadIdeamethod at all.