Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package scalatest

    ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.

    ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.

    Definition Classes
    org
  • trait FixtureAsyncTestSuite extends FixtureSuite with AsyncTestSuite

    The base trait of ScalaTest's "fixture" async testing styles, which enable you to pass fixture objects into tests.

    The base trait of ScalaTest's "fixture" async testing styles, which enable you to pass fixture objects into tests.

    This trait provides a final override of withFixture(OneArgTest), declared in supertrait FixtureSuite, because the withFixture(OneArgTest) lifecycle method assumes synchronous testing. Here is its signature:

    def withFixture(test: OneArgTest): Outcome
    

    The test function interface, OneArgTest, offers an apply method that takes a FixtureParam and returns Outcome:

    // In trait OneArgTest:
    def apply(fixture: FixtureParam): Outcome
    

    Because the result of a test is an Outcome, when the test function returns, the test body must have determined an outcome already. It will already be one of Succeeded, Failed, Canceled, or Pending. This is also true when withFixture(OneArgTest) returns: because the result type of withFixture(OneArgTest) is Outcome, the test body has by definition has already finished execution.

    This trait overrides and makes abstract the runTest method. Subtraits must must implement this method to call withFixture(OneArgAsyncTest) instead of withFixture(OneArgTest), where withFixture(OneArgAsyncTest) is a new method declared in this trait with the following signature and implementation:

    def withFixture(test: OneArgAsyncTest): FutureOutcome = {
      test()
    }
    

    Instead of returning Outcome like withFixture, the withFixture method returns a FutureOutcome. Similarly, the apply method of test function interface, OneArgAsyncTest, returns FutureOutcome:

    // In trait OneArgAsyncTest:
    def apply(fixture: FixtureParam): FutureOutcome
    

    The withFixture method supports async testing, because when the test function returns, the test body has not necessarily finished execution.

    The recommended way to ensure cleanup is performed after a test body finishes execution is to use the complete-lastly syntax, defined in supertrait org.scalatest.CompleteLastly, which will ensure that cleanup will occur whether future-producing code completes abruptly by throwing an exception, or returns normally yielding a future. In the latter case, complete-lastly will register the cleanup code to execute asynchronously when the future completes.

    To enable the stacking of traits that define withFixture(NoArgAsyncTest), it is a good idea to let withFixture(NoArgAsyncTest) invoke the test function instead of invoking the test function directly. To do so, you'll need to convert the OneArgAsyncTest to a NoArgAsyncTest. You can do that by passing the fixture object to the toNoArgAsyncTest method of OneArgAsyncTest. In other words, instead of writing “test(theFixture)”, you'd delegate responsibility for invoking the test function to the withFixture(NoArgAsyncTest) method of the same instance by writing:

    withFixture(test.toNoArgAsyncTest(theFixture))
    

    Thus, the recommended structure of a withFixture implementation that performs cleanup looks like this:

    // Your implementation
    override def withFixture(test: OneArgAsyncTest) = {
    
    // Perform setup here val theFixture = ...
    complete { withFixture(test.toNoArgAsyncTest(theFixture)) // Invoke the test function } lastly { // Perform cleanup here } }

    If you have no cleanup to perform, you can write withFixture like this instead:

    // Your implementation
    override def withFixture(test: OneArgAsyncTest) = {
    
    // Perform setup here val theFixture = ...
    withFixture(test.toNoArgAsyncTest(theFixture)) // Invoke the test function }

    If you want to perform an action only for certain outcomes, you'll need to register code performing that action as a callback on the Future using one of Future registration methods: onComplete, onSuccess, or onFailure. Note that if a test fails, that will be treated as a scala.util.Success(org.scalatest.Failure). So if you want to perform an action if a test fails, for example, you'd register the callaback using onSuccess, like this:

    // Your implementation
    override def withFixture(test: OneArgAsyncTest) = {
    
    // Perform setup here val theFixture = ...
    val futureOutcome = withFixture(test.toNoArgAsyncTest(theFixture)) // Invoke the test function
    futureOutcome onFailedThen { _ => // perform action that you want to occur // only if a test fails here } }

    Lastly, if you want to transform the outcome in some way in withFixture, you'll need to use either the map or transform methods of Future, like this:

    // Your implementation
    override def withFixture(test: OneArgAsyncTest) = {
    
    // Perform setup here val theFixture = ...
    val futureOutcome = withFixture(test.toNoArgAsyncTest(theFixture)) // Invoke the test function
    futureOutcome change { outcome => // transform the outcome into a new outcome here } }

    Note that a NoArgAsyncTest's apply method will only return a Failure if the test completes abruptly with an exception (such as OutOfMemoryError) that should cause the suite to abort rather than the test to fail. Thus usually you would use map to transform future outcomes, not transform, so that such suite-aborting exceptions pass through unchanged. The suite will abort asynchronously with any exception returned in a Failure.

    Definition Classes
    scalatest
  • CheckingEqualizer
  • Equalizer
  • FixtureParam
  • NoArgAsyncTest
  • OneArgAsyncTest
  • ResultOfCompleteInvocation

trait OneArgAsyncTest extends (FixtureParam) => FutureOutcome with TestData

A test function taking no arguments and returning an FutureOutcome.

For more detail and examples, see the relevant section in the documentation for trait fixture.AsyncFlatSpec.

Self Type
OneArgAsyncTest
Source
FixtureAsyncTestSuite.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. OneArgAsyncTest
  2. TestData
  3. Function1
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def apply(fixture: FixtureAsyncTestSuite.FixtureParam): FutureOutcome

    Using the passed FixtureParam, produces a FutureOutcome representing the future outcome of this asynchronous test.

    Using the passed FixtureParam, produces a FutureOutcome representing the future outcome of this asynchronous test.

    fixture

    the FixtureParam

    returns

    an instance of FutureOutcome

    Definition Classes
    OneArgAsyncTest → Function1
  2. abstract val configMap: ConfigMap

    A ConfigMap containing objects that can be used to configure the fixture and test.

    A ConfigMap containing objects that can be used to configure the fixture and test.

    Definition Classes
    TestData
  3. abstract val name: String

    The name of this test.

    The name of this test.

    See the main documentation for this trait for an explanation of the difference between name, text, and scopes.

    Definition Classes
    TestData
  4. abstract val pos: Option[Position]
    Definition Classes
    TestData
  5. abstract val scopes: IndexedSeq[String]

    An immutable IndexedSeq containing the text for any "scopes" enclosing this test, in order from outermost to innermost scope.

    An immutable IndexedSeq containing the text for any "scopes" enclosing this test, in order from outermost to innermost scope.

    See the main documentation for this trait for an explanation of the difference between name, text, and scopes. If a test has no surrounding scopes, this field will contain an empty IndexedSeq.

    Definition Classes
    TestData
  6. abstract val tags: Set[String]

    Tag names for this test.

    Tag names for this test.

    Definition Classes
    TestData
  7. abstract val text: String

    The "text" for this test.

    The "text" for this test.

    See the main documentation for this trait for an explanation of the difference between name, text, and scopes. If a test has no surrounding scopes, this field will contain the same string as name.

    Definition Classes
    TestData

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def andThen[A](g: (FutureOutcome) => A): (FixtureAsyncTestSuite.FixtureParam) => A
    Definition Classes
    Function1
    Annotations
    @unspecialized()
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  7. def compose[A](g: (A) => FixtureAsyncTestSuite.FixtureParam): (A) => FutureOutcome
    Definition Classes
    Function1
    Annotations
    @unspecialized()
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  11. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  18. def toNoArgAsyncTest(fixture: FixtureAsyncTestSuite.FixtureParam): FixtureAsyncTestSuite.NoArgAsyncTest

    Convert this OneArgAsyncTest to a NoArgAsyncTest whose name and configMap methods return the same values as this OneArgAsyncTest, and whose apply method invokes this OneArgAsyncTest's apply method, passing in the given fixture.

    Convert this OneArgAsyncTest to a NoArgAsyncTest whose name and configMap methods return the same values as this OneArgAsyncTest, and whose apply method invokes this OneArgAsyncTest's apply method, passing in the given fixture.

    This method makes it easier to invoke the withFixture method that takes a NoArgAsyncTest. Here's how that might look in a FixtureAsyncTestSuite whose FixtureParam is StringBuilder:

    def withFixture(test: OneArgAsyncTest) = {
      withFixture(test.toNoArgAsyncTest(new StringBuilder))
    }
    

    Invoking this method has no side effect. It just returns a NoArgAsyncTest whose apply method invokes apply on this OneArgAsyncTest, passing in the FixtureParam passed to toNoArgAsyncTest.

    fixture

    the FixtureParam

    returns

    an new instance of NoArgAsyncTest

  19. def toString(): String
    Definition Classes
    Function1 → AnyRef → Any
  20. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  21. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  22. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from TestData

Inherited from AnyRef

Inherited from Any

Ungrouped