akka.testkit

TestKitBase

trait TestKitBase extends AnyRef

Implementation trait behind the akka.testkit.TestKit class: you may use this if inheriting from a concrete class is not possible.

Use of the trait is discouraged because of potential issues with binary backwards compatibility in the future, use at own risk.

This trait requires the concrete class mixing it in to provide an akka.actor.ActorSystem which is available before this traits’s constructor is run. The recommended way is this:

class MyTest extends TestKitBase {
implicit lazy val system = ActorSystem() // may add arguments here
...
}
Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. TestKitBase
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by any2stringfmt
  3. by any2ArrowAssoc
  4. by any2Ensuring
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. implicit abstract val system: ActorSystem

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def +(other: String): String

    Implicit information
    This member is added by an implicit conversion from TestKitBase to StringAdd performed by method any2stringadd in scala.Predef.
    Definition Classes
    StringAdd
  5. def ->[B](y: B): (TestKitBase, B)

    Implicit information
    This member is added by an implicit conversion from TestKitBase to ArrowAssoc[TestKitBase] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  6. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  7. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. def awaitAssert(a: ⇒ Any, max: Duration = Duration.Undefined, interval: Duration = 800.millis): Unit

    Await until the given assert does not throw an exception or the timeout expires, whichever comes first.

    Await until the given assert does not throw an exception or the timeout expires, whichever comes first. If the timeout expires the last exception is thrown.

    If no timeout is given, take it from the innermost enclosing within block.

    Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "akka.test.timefactor".

  10. def awaitCond(p: ⇒ Boolean, max: Duration = Duration.Undefined, interval: Duration = 100.millis, message: String = ""): Unit

    Await until the given condition evaluates to true or the timeout expires, whichever comes first.

    Await until the given condition evaluates to true or the timeout expires, whichever comes first.

    If no timeout is given, take it from the innermost enclosing within block.

    Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "akka.test.timefactor".

  11. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  12. def ensuring(cond: (TestKitBase) ⇒ Boolean, msg: ⇒ Any): TestKitBase

    Implicit information
    This member is added by an implicit conversion from TestKitBase to Ensuring[TestKitBase] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: (TestKitBase) ⇒ Boolean): TestKitBase

    Implicit information
    This member is added by an implicit conversion from TestKitBase to Ensuring[TestKitBase] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: Boolean, msg: ⇒ Any): TestKitBase

    Implicit information
    This member is added by an implicit conversion from TestKitBase to Ensuring[TestKitBase] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. def ensuring(cond: Boolean): TestKitBase

    Implicit information
    This member is added by an implicit conversion from TestKitBase to Ensuring[TestKitBase] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  16. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  17. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  18. def expectMsg[T](max: FiniteDuration, obj: T): T

    Receive one message from the test actor and assert that it equals the given object.

    Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    returns

    the received object

  19. def expectMsg[T](obj: T): T

    Same as expectMsg(remaining, obj), but correctly treating the timeFactor.

  20. def expectMsgAllClassOf[T](max: FiniteDuration, obj: Class[_ <: T]*): Seq[T]

    Receive a number of messages from the test actor matching the given number of classes and assert that for each given class one is received which is of that class (equality, not conformance).

    Receive a number of messages from the test actor matching the given number of classes and assert that for each given class one is received which is of that class (equality, not conformance). This construct is useful when the order in which the objects are received is not fixed. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

  21. def expectMsgAllClassOf[T](obj: Class[_ <: T]*): Seq[T]

    Same as expectMsgAllClassOf(remaining, obj...), but correctly treating the timeFactor.

  22. def expectMsgAllConformingOf[T](max: FiniteDuration, obj: Class[_ <: T]*): Seq[T]

    Receive a number of messages from the test actor matching the given number of classes and assert that for each given class one is received which conforms to that class (and vice versa).

    Receive a number of messages from the test actor matching the given number of classes and assert that for each given class one is received which conforms to that class (and vice versa). This construct is useful when the order in which the objects are received is not fixed. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    Beware that one object may satisfy all given class constraints, which may be counter-intuitive.

  23. def expectMsgAllConformingOf[T](obj: Class[_ <: T]*): Seq[T]

    Same as expectMsgAllConformingOf(remaining, obj...), but correctly treating the timeFactor.

  24. def expectMsgAllOf[T](max: FiniteDuration, obj: T*): Seq[T]

    Receive a number of messages from the test actor matching the given number of objects and assert that for each given object one is received which equals it and vice versa.

    Receive a number of messages from the test actor matching the given number of objects and assert that for each given object one is received which equals it and vice versa. This construct is useful when the order in which the objects are received is not fixed. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

      dispatcher ! SomeWork1()
      dispatcher ! SomeWork2()
      expectMsgAllOf(1 second, Result1(), Result2())
    

  25. def expectMsgAllOf[T](obj: T*): Seq[T]

    Same as expectMsgAllOf(remaining, obj...), but correctly treating the timeFactor.

  26. def expectMsgAnyClassOf[C](max: FiniteDuration, obj: Class[_ <: C]*): C

    Receive one message from the test actor and assert that it conforms to one of the given classes.

    Receive one message from the test actor and assert that it conforms to one of the given classes. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    returns

    the received object

  27. def expectMsgAnyClassOf[C](obj: Class[_ <: C]*): C

    Same as expectMsgAnyClassOf(remaining, obj...), but correctly treating the timeFactor.

  28. def expectMsgAnyOf[T](max: FiniteDuration, obj: T*): T

    Receive one message from the test actor and assert that it equals one of the given objects.

    Receive one message from the test actor and assert that it equals one of the given objects. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    returns

    the received object

  29. def expectMsgAnyOf[T](obj: T*): T

    Same as expectMsgAnyOf(remaining, obj...), but correctly treating the timeFactor.

  30. def expectMsgClass[C](max: FiniteDuration, c: Class[C]): C

    Receive one message from the test actor and assert that it conforms to the given class.

    Receive one message from the test actor and assert that it conforms to the given class. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    returns

    the received object

  31. def expectMsgClass[C](c: Class[C]): C

    Same as expectMsgClass(remaining, c), but correctly treating the timeFactor.

  32. def expectMsgPF[T](max: Duration = Duration.Undefined, hint: String = "")(f: PartialFunction[Any, T]): T

    Receive one message from the test actor and assert that the given partial function accepts it.

    Receive one message from the test actor and assert that the given partial function accepts it. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    Use this variant to implement more complicated or conditional processing.

    returns

    the received object as transformed by the partial function

  33. def expectMsgType[T](max: FiniteDuration)(implicit t: ClassTag[T]): T

    Receive one message from the test actor and assert that it conforms to the given type (after erasure).

    Receive one message from the test actor and assert that it conforms to the given type (after erasure). Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    returns

    the received object

  34. def expectMsgType[T](implicit t: ClassTag[T]): T

    Same as expectMsgType[T](remaining), but correctly treating the timeFactor.

  35. def expectNoMsg(max: FiniteDuration): Unit

    Assert that no message is received for the specified time.

  36. def expectNoMsg(): Unit

    Same as expectNoMsg(remaining), but correctly treating the timeFactor.

  37. def expectTerminated(target: ActorRef, max: Duration = Duration.Undefined): Terminated

    Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef.

    Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    returns

    the received Terminated message

  38. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  39. def fishForMessage(max: Duration = Duration.Undefined, hint: String = "")(f: PartialFunction[Any, Boolean]): Any

    Hybrid of expectMsgPF and receiveWhile: receive messages while the partial function matches and returns false.

    Hybrid of expectMsgPF and receiveWhile: receive messages while the partial function matches and returns false. Use it to ignore certain messages while waiting for a specific message.

    returns

    the last received messsage, i.e. the first one for which the partial function returned true

  40. def formatted(fmtstr: String): String

    Implicit information
    This member is added by an implicit conversion from TestKitBase to StringFormat performed by method any2stringfmt in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  41. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  42. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  43. def ignoreMsg(f: PartialFunction[Any, Boolean]): Unit

    Ignore all messages in the test actor for which the given partial function returns true.

  44. def ignoreNoMsg(): Unit

    Stop ignoring messages in the test actor.

  45. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  46. def lastSender: ActorRef

  47. def msgAvailable: Boolean

    Query queue status.

  48. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  49. final def notify(): Unit

    Definition Classes
    AnyRef
  50. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  51. def now: FiniteDuration

    Obtain current time (System.nanoTime) as Duration.

  52. def receiveN(n: Int, max: FiniteDuration): Seq[AnyRef]

    Receive N messages in a row before the given deadline.

  53. def receiveN(n: Int): Seq[AnyRef]

    Same as receiveN(n, remaining) but correctly taking into account Duration.

    Same as receiveN(n, remaining) but correctly taking into account Duration.timeFactor.

  54. def receiveOne(max: Duration): AnyRef

    Receive one message from the internal queue of the TestActor.

    Receive one message from the internal queue of the TestActor. If the given duration is zero, the queue is polled (non-blocking).

    This method does NOT automatically scale its Duration parameter!

  55. def receiveWhile[T](max: Duration = Duration.Undefined, idle: Duration = Duration.Inf, messages: Int = Int.MaxValue)(f: PartialFunction[AnyRef, T]): Seq[T]

    Receive a series of messages until one does not match the given partial function or the idle timeout is met (disabled by default) or the overall maximum duration is elapsed.

    Receive a series of messages until one does not match the given partial function or the idle timeout is met (disabled by default) or the overall maximum duration is elapsed. Returns the sequence of messages.

    Note that it is not an error to hit the max duration in this case.

    One possible use of this method is for testing whether messages of certain characteristics are generated at a certain rate:

    test ! ScheduleTicks(100 millis)
    val series = receiveWhile(750 millis) {
        case Tick(count) => count
    }
    assert(series == (1 to 7).toList)
    

  56. def remaining: FiniteDuration

    Obtain time remaining for execution of the innermost enclosing within block or missing that it returns the properly dilated default for this case from settings (key "akka.

    Obtain time remaining for execution of the innermost enclosing within block or missing that it returns the properly dilated default for this case from settings (key "akka.test.single-expect-default").

  57. def remainingOr(duration: FiniteDuration): FiniteDuration

    Obtain time remaining for execution of the innermost enclosing within block or missing that it returns the given duration.

  58. def setAutoPilot(pilot: AutoPilot): Unit

    Install an AutoPilot to drive the testActor: the AutoPilot will be run for each received message and can be used to send or forward messages, etc.

    Install an AutoPilot to drive the testActor: the AutoPilot will be run for each received message and can be used to send or forward messages, etc. Each invocation must return the AutoPilot for the next round.

  59. def shutdown(actorSystem: ActorSystem, duration: Duration = 5.seconds.dilated.min(10.seconds), verifySystemShutdown: Boolean = false): Unit

    Shut down an actor system and wait for termination.

    Shut down an actor system and wait for termination. On failure debug output will be logged about the remaining actors in the system.

    If verifySystemShutdown is true, then an exception will be thrown on failure.

  60. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  61. val testActor: ActorRef

    ActorRef of the test actor.

    ActorRef of the test actor. Access is provided to enable e.g. registration as message target.

  62. val testKitSettings: TestKitSettings

  63. def toString(): String

    Definition Classes
    AnyRef → Any
  64. def unwatch(ref: ActorRef): ActorRef

    Have the testActor stop watching someone (i.

    Have the testActor stop watching someone (i.e. context.unwatch(...)).

  65. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  66. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  67. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  68. def watch(ref: ActorRef): ActorRef

    Have the testActor watch someone (i.

    Have the testActor watch someone (i.e. context.watch(...)).

  69. def within[T](max: FiniteDuration)(f: ⇒ T): T

    Same as calling within(0 seconds, max)(f).

  70. def within[T](min: FiniteDuration, max: FiniteDuration)(f: ⇒ T): T

    Execute code block while bounding its execution time between min and max.

    Execute code block while bounding its execution time between min and max. within blocks may be nested. All methods in this trait which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing within block.

    Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "akka.test.timefactor", while the min Duration is not.

    val ret = within(50 millis) {
            test ! "ping"
            expectMsgClass(classOf[String])
          }
    

  71. def [B](y: B): (TestKitBase, B)

    Implicit information
    This member is added by an implicit conversion from TestKitBase to ArrowAssoc[TestKitBase] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Shadowed Implicit Value Members

  1. val self: Any

    Implicit information
    This member is added by an implicit conversion from TestKitBase to StringAdd performed by method any2stringadd in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (testKitBase: StringAdd).self
    Definition Classes
    StringAdd
  2. val self: Any

    Implicit information
    This member is added by an implicit conversion from TestKitBase to StringFormat performed by method any2stringfmt in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (testKitBase: StringFormat).self
    Definition Classes
    StringFormat

Deprecated Value Members

  1. def x: TestKitBase

    Implicit information
    This member is added by an implicit conversion from TestKitBase to ArrowAssoc[TestKitBase] performed by method any2ArrowAssoc in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (testKitBase: ArrowAssoc[TestKitBase]).x
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use leftOfArrow instead

  2. def x: TestKitBase

    Implicit information
    This member is added by an implicit conversion from TestKitBase to Ensuring[TestKitBase] performed by method any2Ensuring in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (testKitBase: Ensuring[TestKitBase]).x
    Definition Classes
    Ensuring
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use resultOfEnsuring instead

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from TestKitBase to StringAdd

Inherited by implicit conversion any2stringfmt from TestKitBase to StringFormat

Inherited by implicit conversion any2ArrowAssoc from TestKitBase to ArrowAssoc[TestKitBase]

Inherited by implicit conversion any2Ensuring from TestKitBase to Ensuring[TestKitBase]

Ungrouped