ScalaTest 1.1
|
|
org/scalatest/junit/JUnitSuite.scala
]
trait
JUnitSuite
extends
Suite with
AssertionsForJUnitassertEquals
, 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) } }
To execute JUnitSuite
s with ScalaTest's Runner
, you must include JUnit's jar file on the class path or runpath.
This version of JUnitSuite
was tested with JUnit version 4.4.
Instances of this trait are not thread safe.
Method Summary | |
override def
|
expectedTestCount
(filter : Filter) : Int
Returns the number of tests expected to be run by JUnit when
run is invoked
on this JUnitSuite . |
override def
|
run
(testName : scala.Option[java.lang.String], report : Reporter, stopper : Stopper, filter : Filter, configMap : scala.collection.immutable.Map[java.lang.String, Any], distributor : scala.Option[Distributor], tracker : Tracker) : Unit
Runs this suite of tests.
|
protected override final def
|
runNestedSuites
(reporter : Reporter, stopper : Stopper, filter : Filter, configMap : scala.collection.immutable.Map[java.lang.String, Any], distributor : scala.Option[Distributor], tracker : Tracker) : Unit
Throws
UnsupportedOperationException , because this method is unused by this
trait, given this trait's run method delegates to JUnit to run
its tests. |
protected override final def
|
runTest
(testName : java.lang.String, reporter : Reporter, stopper : Stopper, configMap : scala.collection.immutable.Map[java.lang.String, Any], tracker : Tracker) : Unit
Throws
UnsupportedOperationException , because this method is unused by this
trait, given this traits's run method delegates to JUnit to run
its tests. |
protected override final def
|
runTests
(testName : scala.Option[java.lang.String], reporter : Reporter, stopper : Stopper, filter : Filter, configMap : scala.collection.immutable.Map[java.lang.String, Any], distributor : scala.Option[Distributor], tracker : Tracker) : Unit
Throws
UnsupportedOperationException , because this method is unused by this
trait, given this trait's run method delegates to JUnit to run
its tests. |
override def
|
tags
: scala.collection.immutable.Map[java.lang.String, scala.collection.immutable.Set[java.lang.String]]
A
Map whose keys are String tag names with which tests in this Suite are marked, and
whose values are the Set of test names marked with each tag. If this Suite contains no tags, this
method returns an empty Map . |
override def
|
testNames
: scala.collection.immutable.Set[java.lang.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. |
protected override final def
|
withFixture
(test : NoArgTest) : Unit
Throws
UnsupportedOperationException , because this method is unused by this
class, given this class's run method delegates to JUnit to run
its tests. |
Methods inherited from Suite | |
nestedSuites, execute, execute, execute, execute, groups, suiteName, pending, pendingUntilFixed |
Methods inherited from Assertions | |
assert, assert, assert, assert, convertToEqualizer, intercept, expect, expect, fail, fail, fail, fail |
Methods inherited from AnyRef | |
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
Methods inherited from Any | |
==, !=, isInstanceOf, asInstanceOf |
Method Details |
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 fixtureprotected override final
def
runNestedSuites(reporter : Reporter, stopper : Stopper, filter : Filter, configMap : scala.collection.immutable.Map[java.lang.String, Any], distributor : scala.Option[Distributor], tracker : Tracker) : Unit
UnsupportedOperationException
, because this method is unused by this
trait, given this trait'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.
reporter -
the Reporter
to which results will be reportedstopper -
the Stopper
that will be consulted to determine whether to stop execution early.filter -
a Filter
with which to filter tests based on their tagsconfigMap -
a Map
of key-value pairs that can be used by the executing Suite
of tests.distributor -
an optional Distributor
, into which to put nested Suite
s to be run by another entity, such as concurrently by a pool of threads. If None
, nested Suite
s will be run sequentially.tracker -
a Tracker
tracking Ordinal
s being fired by the current thread.UnsupportedOperationException -
always.protected override final
def
runTests(testName : scala.Option[java.lang.String], reporter : Reporter, stopper : Stopper, filter : Filter, configMap : scala.collection.immutable.Map[java.lang.String, Any], distributor : scala.Option[Distributor], tracker : Tracker) : Unit
UnsupportedOperationException
, because this method is unused by this
trait, given this trait'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
.reporter -
the Reporter
to which results will be reportedstopper -
the Stopper
that will be consulted to determine whether to stop execution early.filter -
a Filter
with which to filter tests based on their tagsconfigMap -
a Map
of key-value pairs that can be used by the executing Suite
of tests.distributor -
an optional Distributor
, into which to put nested Suite
s to be run by another entity, such as concurrently by a pool of threads. If None
, nested Suite
s will be run sequentially.tracker -
a Tracker
tracking Ordinal
s being fired by the current thread.UnsupportedOperationException -
always.protected override final
def
runTest(testName : java.lang.String, reporter : Reporter, stopper : Stopper, configMap : scala.collection.immutable.Map[java.lang.String, Any], tracker : Tracker) : Unit
UnsupportedOperationException
, because this method is unused by this
trait, given this traits'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.reporter -
the Reporter
to which results will be reportedstopper -
the Stopper
that will be consulted to determine whether to stop execution early.configMap -
a Map
of key-value pairs that can be used by the executing Suite
of tests.tracker -
a Tracker
tracking Ordinal
s being fired by the current thread.UnsupportedOperationException -
always.override
def
testNames : scala.collection.immutable.Set[java.lang.String]
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.
run
is invoked
on this JUnitSuite
.
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,
less the number of tests that were annotated with org.junit.Ignore
.
override
def
tags : scala.collection.immutable.Map[java.lang.String, scala.collection.immutable.Set[java.lang.String]]
Map
whose keys are String
tag names with which tests in this Suite
are marked, and
whose values are the Set
of test names marked with each tag. If this Suite
contains no tags, this
method returns an empty Map
.
This trait's implementation of this method uses Java reflection to discover any Java annotations attached to its test methods. The
fully qualified name of each unique annotation that extends TagAnnotation
is considered a tag. This trait's
implementation of this method, therefore, places one key/value pair into to the
Map
for each unique tag annotation name discovered through reflection. The mapped value for each tag name key will contain
the test method name, as provided via the testNames
method.
Subclasses may override this method to define and/or discover tags in a custom manner, but overriding method implementations
should never return an empty Set
as a value. If a tag has no tests, its name should not appear as a key in the
returned Map
.
Note, the TagAnnotation
annotation was introduced in ScalaTest 1.0, when "groups" were renamed
to "tags." In 1.0 and 1.1, the TagAnnotation
will continue to not be required by an annotation on a Suite
method. Any annotation on a Suite
method will be considered a tag until 1.2, to give users time to add
TagAnnotation
s on any tag annotations they made prior to the 1.0 release. From 1.2 onward, only annotations
themselves annotated by TagAnnotation
will be considered tag annotations.
override
def
run(testName : scala.Option[java.lang.String], report : Reporter, stopper : Stopper, filter : Filter, configMap : scala.collection.immutable.Map[java.lang.String, Any], distributor : scala.Option[Distributor], tracker : Tracker) : Unit
If testName
is None
, this trait's implementation of this method
calls these two methods on this object in this order:
runNestedSuites(report, stopper, tagsToInclude, tagsToExclude, configMap, distributor)
runTests(testName, report, stopper, tagsToInclude, tagsToExclude, configMap)
If testName
is defined, then this trait's implementation of this method
calls runTests
, but does not call runNestedSuites
. This behavior
is part of the contract of this method. Subclasses that override run
must take
care not to call runNestedSuites
if testName
is defined. (The
OneInstancePerTest
trait depends on this behavior, for example.)
Subclasses and subtraits that override this run
method can implement them without
invoking either the runTests
or runNestedSuites
methods, which
are invoked by this trait's implementation of this method. It is recommended, but not required,
that subclasses and subtraits that override run
in a way that does not
invoke runNestedSuites
also override runNestedSuites
and make it
final. Similarly it is recommended, but not required,
that subclasses and subtraits that override run
in a way that does not
invoke runTests
also override runTests
(and runTest
,
which this trait's implementation of runTests
calls) and make it
final. The implementation of these final methods can either invoke the superclass implementation
of the method, or throw an UnsupportedOperationException
if appropriate. The
reason for this recommendation is that ScalaTest includes several traits that override
these methods to allow behavior to be mixed into a Suite
. For example, trait
BeforeAndAfterEach
overrides runTests
s. In a Suite
subclass that no longer invokes runTests
from run
, the
BeforeAndAfterEach
trait is not applicable. Mixing it in would have no effect.
By making runTests
final in such a Suite
subtrait, you make
the attempt to mix BeforeAndAfterEach
into a subclass of your subtrait
a compiler error. (It would fail to compile with a complaint that BeforeAndAfterEach
is trying to override runTests
, which is a final method in your trait.)
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
.reporter -
the Reporter
to which results will be reportedstopper -
the Stopper
that will be consulted to determine whether to stop execution early.filter -
a Filter
with which to filter tests based on their tagsconfigMap -
a Map
of key-value pairs that can be used by the executing Suite
of tests.distributor -
an optional Distributor
, into which to put nested Suite
s to be run by another entity, such as concurrently by a pool of threads. If None
, nested Suite
s will be run sequentially.tracker -
a Tracker
tracking Ordinal
s being fired by the current thread.NullPointerException -
if any passed parameter is null
.IllegalArgumentException -
if testName
is defined, but no test with the specified test name exists in this Suite
ScalaTest 1.1
|
|