trait
Informer
extends AnyRef
Abstract Value Members
-
def
apply
(message: String): Unit
Concrete Value Members
-
def
!=
(arg0: AnyRef): Boolean
-
def
!=
(arg0: Any): Boolean
-
def
##
(): Int
-
def
==
(arg0: AnyRef): Boolean
-
def
==
(arg0: Any): Boolean
-
def
asInstanceOf
[T0]
: T0
-
def
clone
(): AnyRef
-
def
eq
(arg0: AnyRef): Boolean
-
def
equals
(arg0: Any): Boolean
-
def
finalize
(): Unit
-
def
getClass
(): java.lang.Class[_]
-
def
hashCode
(): Int
-
def
isInstanceOf
[T0]
: Boolean
-
def
ne
(arg0: AnyRef): Boolean
-
def
notify
(): Unit
-
def
notifyAll
(): Unit
-
def
synchronized
[T0]
(arg0: ⇒ T0): T0
-
def
toString
(): String
-
def
wait
(): Unit
-
def
wait
(arg0: Long, arg1: Int): Unit
-
def
wait
(arg0: Long): Unit
Inherited from AnyRef
Inherited from Any
Trait to which custom information about a running suite of tests can be reported.
An
Informeris essentially used to wrap aReporterand provide easy ways to send custom information to thatReportervia anInfoProvidedevent.Informercontains anapplymethod that takes an object. TheInformerwill invoketoStringon the passed object and forward the resulting string to theReporteras themessageparameter of anInfoProvidedevent.Here's an example of using an
Informerin aSuitesubclass:import org.scalatest._ class MySuite extends Suite { def testAddition(info: Informer) { assert(1 + 1 === 2) info("Addition seems to work") } }If you run this
Suitefrom the interpreter, you will see the message included in the printed report:Traits
FunSuite,Spec,FlatSpec,WordSpec,FeatureSpec, and their sister traits inorg.scalatest.fixturepackage declare an implicitinfomethod that returns anInformer. This implicitinfois used, for example, to enable the syntax offered by theGivenWhenThentrait, which contains methods that take an implicitInformer. Here's an example of aFeatureSpecthat mixes inGivenWhenThen:import org.scalatest.FeatureSpec import org.scalatest.GivenWhenThen class ArithmeticSpec extends FeatureSpec with GivenWhenThen { feature("Integer arithmetic") { scenario("addition") { given("two integers") val x = 2 val y = 3 when("they are added") val sum = x + y then("the result is the sum of the two numbers") assert(sum === 5) } scenario("subtraction") { given("two integers") val x = 7 val y = 2 when("one is subtracted from the other") val diff = x - y then("the result is the difference of the two numbers") assert(diff === 5) } } }Were you to run this
FeatureSpecin the interpreter, you would see the following messages included in the printed report:scala> (new ArithmeticFeatureSpec).run() Feature: Integer arithmetic Scenario: addition Given two integers When they are added Then the result is the sum of the two numbers Scenario: subtraction Given two integers When one is subtracted from the other Then the result is the difference of the two numbers