org.scalatest.fun

trait FunSuite2

[source: org/scalatest/fun/FunSuite2.scala]

trait FunSuite2[F, U]
extends Suite
A suite of tests in which each test is represented as a function value that takes 2 parameters that are intended to serve as fixture objects for the suite's tests. Clients must parameterize FunSuite2 with the types of each of the fixture objects. Most often this will be done explicitly by subclasses that have tests that need the fixture objects. Here's an example:
 class MySuite extends FunSuite2[Float, Int] {

   testWithFixture("example test") {
     (f, i) => {
       // test code that uses the passed fixture objects...
     }
   }

   def withFixture(f: (Float, Int) => Unit) {

      // Create the fixture objects (as in JUnit 3's setUp method)
      val f = 1.1f
val float = 1.1f // Pass the fixture objects to the test function f(f, i) // If need be, perform any cleanup (as in JUnit 3's tearDown method) } }
This is a contrived example, because normally you would only pass fixture objects in this manner if they are mutable. (The reason we used immutable objects in this example was just to make the type names fit more easily on the page.) If they aren't mutable, then the fixture objects can simply be referenced from instance variables and shared by all test methods that need them. Since they aren't mutable, they can't be "corrupted" by one test and rendered unusable by the next. For mutable fixture objects, though, this trait allows you to reinitialize and pass in a fresh set of fixture objects to each test function that needs them.
Author
Bill Venners
Method Summary
override def groups : scala.collection.immutable.Map[java.lang.String, scala.collection.immutable.Set[java.lang.String]]
A Map whose keys are String group names to which tests in this FunSuite2 belong, and values the Set of test names that belong to each group. If this FunSuite2 contains no groups, this method returns an empty Map.
protected def ignore (testName : java.lang.String, testGroups : Group*)(f : => Unit) : Unit
Register a test to ignore, which has the specified name, optional groups, and function value that takes no arguments. This method will register the test for later ignoring via an invocation of one of the execute methods. This method exists to make it easy to ignore an existing test method by changing the call to test to ignore without deleting or commenting out the actual test code. The test will not be executed, but a report will be sent that indicates the test was ignored. The passed test name must not have been registered previously on this FunSuite2 instance.
protected def ignoreWithFixture (testName : java.lang.String, testGroups : Group*)(f : (F, U) => Unit) : Unit
Register a test to ignore, which has the specified name, optional groups, and function value that takes 2 arguments. This method will register the test for later ignoring via an invocation of one of the execute methods. This method exists to make it easy to ignore an existing test method by changing the call to testWithFixture to ignoreWithFixture without deleting or commenting out the actual test code. The test will not be executed, but a report will be sent that indicates the test was ignored. The passed test name must not have been registered previously on this FunSuite2 instance.
protected def ignoreWithFixtureAndReporter (testName : java.lang.String, testGroups : Group*)(f : (F, U, Reporter) => Unit) : Unit
Register a test to ignore, which has the specified name, optional groups, and function value that takes 2 arguments and a Reporter. This method will register the test for later ignoring via an invocation of one of the execute methods. This method exists to make it easy to ignore an existing test method by changing the call to testWithFixtureAndReporter to ignoreWithFixtureAndReporter without deleting or commenting out the actual test code. The test will not be executed, but a report will be sent that indicates the test was ignored. The passed test name must not have been registered previously on this FunSuite2 instance.
protected def ignoreWithReporter (testName : java.lang.String, testGroups : Group*)(f : (Reporter) => Unit) : Unit
Register a test to ignore, which has the specified name, optional groups, and function value that takes a Reporter. This method will register the test for later ignoring via an invocation of one of the execute methods. This method exists to make it easy to ignore an existing test method by changing the call to testWithReporter to ignoreWithReporter without deleting or commenting out the actual test code. The test will not be executed, but a report will be sent that indicates the test was ignored. The passed test name must not have been registered previously on this FunSuite2 instance.
protected override def runTest (testName : java.lang.String, reporter : Reporter, stopper : Stopper, properties : scala.collection.immutable.Map[java.lang.String, Any]) : Unit
Run a test. This trait's implementation runs the test registered with the name specified by testName.
protected def test (testName : java.lang.String, testGroups : Group*)(f : => Unit) : Unit
Register a test with the specified name, optional groups, and function value that takes no arguments. This method will register the test for later execution via an invocation of one of the execute methods. The passed test name must not have been registered previously on this FunSuite2 instance.
override def testNames : scala.collection.immutable.Set[java.lang.String]
An immutable Set of test names. If this FunSuite2 contains no tests, this method returns an empty Set.
protected def testWithFixture (testName : java.lang.String, testGroups : Group*)(f : (F, U) => Unit) : Unit
Register a test with the specified name, optional groups, and function value that takes 2 arguments. This method will register the test for later execution via an invocation of one of the execute methods. The passed test name must not have been registered previously on this FunSuite2 instance. This trait will not invoke any test functions registered via this method directly, but will instead pass each test function registered with this method to withFixture. It is the responsibility of subclass implementations of withFixture to invoke the test method, passing in the required fixture objects.
protected def testWithFixtureAndReporter (testName : java.lang.String, testGroups : Group*)(f : (F, U, Reporter) => Unit) : Unit
Register a test with the specified name, optional groups, and function value that takes 2 arguments and a Reporter. This method will register the test for later execution via an invocation of one of the execute methods. The Reporter passed to execute, or a Reporter that wraps it, will be partially applied to the function value, and the resulting function will be passed to withFixture. Thus, this trait will not invoke any test functions registered via this method directly, but will instead pass each test function registered with this method to withFixture. It is the responsibility of subclass implementations of withFixture to invoke the test method, passing in the required fixture objects. The passed test name must not have been registered previously on this FunSuite2 instance.
protected def testWithReporter (testName : java.lang.String, testGroups : Group*)(f : (Reporter) => Unit) : Unit
Register a test with the specified name, optional groups, and function value that takes a Reporter. This method will register the test for later execution via an invocation of one of the execute methods. The Reporter passed to execute, or a Reporter that wraps it, will be passed to the function value. The passed test name must not have been registered previously on this FunSuite2 instance.
protected abstract def withFixture (f : (F, U) => Unit) : Unit
Create fixture objects and pass them to the specified test function value, f, performing any necessary cleanup afterwards. This method serves the same purpose as the setUp and tearDown methods of JUnit 3, the @Before and @After method annotations of JUnit 4, or the @Configuration(beforeTestMethod = true) and @Configuration(afterTestMethod = true) method annotations of TestNG. Override this method if you have fixture objects that are either themselves mutable, or provide access to some other resource that tests may mutate in some way that needs to be reset for other tests.
Methods inherited from Suite
nestedSuites, execute, execute, runTests, execute, runNestedSuites, suiteName, expectedTestCount, fail, fail, fail, fail, assert, assert, assert, assert, convertToEqualizer, intercept, intercept, expect, expect
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
protected abstract def withFixture(f : (F, U) => Unit) : Unit
Create fixture objects and pass them to the specified test function value, f, performing any necessary cleanup afterwards. This method serves the same purpose as the setUp and tearDown methods of JUnit 3, the @Before and @After method annotations of JUnit 4, or the @Configuration(beforeTestMethod = true) and @Configuration(afterTestMethod = true) method annotations of TestNG. Override this method if you have fixture objects that are either themselves mutable, or provide access to some other resource that tests may mutate in some way that needs to be reset for other tests.

protected def test(testName : java.lang.String, testGroups : Group*)(f : => Unit) : Unit
Register a test with the specified name, optional groups, and function value that takes no arguments. This method will register the test for later execution via an invocation of one of the execute methods. The passed test name must not have been registered previously on this FunSuite2 instance.
Throws
IllegalArgumentException - if testName had been registered previously

protected def testWithReporter(testName : java.lang.String, testGroups : Group*)(f : (Reporter) => Unit) : Unit
Register a test with the specified name, optional groups, and function value that takes a Reporter. This method will register the test for later execution via an invocation of one of the execute methods. The Reporter passed to execute, or a Reporter that wraps it, will be passed to the function value. The passed test name must not have been registered previously on this FunSuite2 instance.
Throws
IllegalArgumentException - if testName had been registered previously

protected def ignore(testName : java.lang.String, testGroups : Group*)(f : => Unit) : Unit
Register a test to ignore, which has the specified name, optional groups, and function value that takes no arguments. This method will register the test for later ignoring via an invocation of one of the execute methods. This method exists to make it easy to ignore an existing test method by changing the call to test to ignore without deleting or commenting out the actual test code. The test will not be executed, but a report will be sent that indicates the test was ignored. The passed test name must not have been registered previously on this FunSuite2 instance.
Throws
IllegalArgumentException - if testName had been registered previously

protected def ignoreWithReporter(testName : java.lang.String, testGroups : Group*)(f : (Reporter) => Unit) : Unit
Register a test to ignore, which has the specified name, optional groups, and function value that takes a Reporter. This method will register the test for later ignoring via an invocation of one of the execute methods. This method exists to make it easy to ignore an existing test method by changing the call to testWithReporter to ignoreWithReporter without deleting or commenting out the actual test code. The test will not be executed, but a report will be sent that indicates the test was ignored. The passed test name must not have been registered previously on this FunSuite2 instance.
Throws
IllegalArgumentException - if testName had been registered previously

protected def testWithFixture(testName : java.lang.String, testGroups : Group*)(f : (F, U) => Unit) : Unit
Register a test with the specified name, optional groups, and function value that takes 2 arguments. This method will register the test for later execution via an invocation of one of the execute methods. The passed test name must not have been registered previously on this FunSuite2 instance. This trait will not invoke any test functions registered via this method directly, but will instead pass each test function registered with this method to withFixture. It is the responsibility of subclass implementations of withFixture to invoke the test method, passing in the required fixture objects.
Throws
IllegalArgumentException - if testName had been registered previously

protected def testWithFixtureAndReporter(testName : java.lang.String, testGroups : Group*)(f : (F, U, Reporter) => Unit) : Unit
Register a test with the specified name, optional groups, and function value that takes 2 arguments and a Reporter. This method will register the test for later execution via an invocation of one of the execute methods. The Reporter passed to execute, or a Reporter that wraps it, will be partially applied to the function value, and the resulting function will be passed to withFixture. Thus, this trait will not invoke any test functions registered via this method directly, but will instead pass each test function registered with this method to withFixture. It is the responsibility of subclass implementations of withFixture to invoke the test method, passing in the required fixture objects. The passed test name must not have been registered previously on this FunSuite2 instance.
Throws
IllegalArgumentException - if testName had been registered previously

protected def ignoreWithFixture(testName : java.lang.String, testGroups : Group*)(f : (F, U) => Unit) : Unit
Register a test to ignore, which has the specified name, optional groups, and function value that takes 2 arguments. This method will register the test for later ignoring via an invocation of one of the execute methods. This method exists to make it easy to ignore an existing test method by changing the call to testWithFixture to ignoreWithFixture without deleting or commenting out the actual test code. The test will not be executed, but a report will be sent that indicates the test was ignored. The passed test name must not have been registered previously on this FunSuite2 instance.
Throws
IllegalArgumentException - if testName had been registered previously

protected def ignoreWithFixtureAndReporter(testName : java.lang.String, testGroups : Group*)(f : (F, U, Reporter) => Unit) : Unit
Register a test to ignore, which has the specified name, optional groups, and function value that takes 2 arguments and a Reporter. This method will register the test for later ignoring via an invocation of one of the execute methods. This method exists to make it easy to ignore an existing test method by changing the call to testWithFixtureAndReporter to ignoreWithFixtureAndReporter without deleting or commenting out the actual test code. The test will not be executed, but a report will be sent that indicates the test was ignored. The passed test name must not have been registered previously on this FunSuite2 instance.
Throws
IllegalArgumentException - if testName had been registered previously

override def testNames : scala.collection.immutable.Set[java.lang.String]
An immutable Set of test names. If this FunSuite2 contains no tests, this method returns an empty Set.

This trait's implementation of this method will return a set that contains the names of all registered tests. The set's iterator will return those names in the order in which the tests were registered.

Overrides
Suite.testNames

protected override def runTest(testName : java.lang.String, reporter : Reporter, stopper : Stopper, properties : scala.collection.immutable.Map[java.lang.String, Any]) : Unit
Run a test. This trait's implementation runs the test registered with the name specified by testName.
Parameters
testName - the name of one test to execute.
reporter - the Reporter to which results will be reported
stopper - the Stopper that will be consulted to determine whether to stop execution early.
properties - a Map of properties that can be used by the executing Suite of tests.
Throws
NullPointerException - if any of testName, reporter, stopper, or properties is null.
Overrides
Suite.runTest

override def groups : scala.collection.immutable.Map[java.lang.String, scala.collection.immutable.Set[java.lang.String]]
A Map whose keys are String group names to which tests in this FunSuite2 belong, and values the Set of test names that belong to each group. If this FunSuite2 contains no groups, this method returns an empty Map.

This trait's implementation returns groups that were passed as strings contained in Group objects passed to methods test, testWithReporter, ignore, and ignoreWithReporter.

Overrides
Suite.groups


Copyright (C) 2001-2008 Artima, Inc. All rights reserved.