ScalaTest 1.1
|
|
trait
ConductorMultiFixture
extends
AnyRefConductor
fixture into tests, for use
in suites such as MultipleFixtureFunSuite
or MultipleFixtureSpec
,
which facilitate writing tests that take different types of fixtures.
Here's an example of the use of this trait to test the ArrayBlockingQueue
concurrency abstraction from java.util.concurrent
:
import org.scalatest.fixture.MultipleFixtureFunSuite import org.scalatest.concurrent.ConductorMultiFixture import org.scalatest.matchers.ShouldMatchers import java.util.concurrent.ArrayBlockingQueue class ArrayBlockingQueueSuite extends MultipleFixtureFunSuite with ConductorMultiFixture with ShouldMatchers { test("calling put on a full queue blocks the producer thread") { (conductor: Conductor) => import conductor._ val buf = new ArrayBlockingQueue[Int](1) thread("producer") { buf put 42 buf put 17 beat should be (1) } thread("consumer") { waitForBeat(1) buf.take should be (42) buf.take should be (17) } whenFinished { buf should be ('empty) } } test("calling take on an empty queue blocks the consumer thread") { (conductor: Conductor) => import conductor._ val buf = new ArrayBlockingQueue[Int](1) thread("producer") { waitForBeat(1) buf put 42 buf put 17 } thread("consumer") { buf.take should be (42) buf.take should be (17) beat should be (1) } whenFinished { buf should be ('empty) } } }
For an explanation of how these tests work, see the documentation for Conductor
.
Method Summary | |
implicit def
|
withConductorFixture
(fun : (Conductor) => Unit) : (scala.collection.immutable.Map) => Unit
Creates a new
Conductor , passes the Conductor to the
specified test function, and ensures that conduct gets invoked
on the Conductor . |
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 |
implicit
def
withConductorFixture(fun : (Conductor) => Unit) : (scala.collection.immutable.Map) => Unit
Conductor
, passes the Conductor
to the
specified test function, and ensures that conduct
gets invoked
on the Conductor
.
After the test function returns (so long as it returns normally and doesn't
complete abruptly with an exception), this method will determine whether the
conduct
method has already been called (by invoking
conductingHasBegun
on the Conductor
). If not,
this method will invoke conduct
to ensure that the
multi-threaded test is actually conducted.
ScalaTest 1.1
|
|