ScalaTest 0.9.5
|
|
org/scalatest/Informer.scala
]
trait
Informer
extends
AnyRefInformer
contains two apply
methods, one which takes
a string and the other a Report
. An Informer
is essentially
used to wrap a Reporter
and provide easy ways to send custom information
to that Reporter
via its infoProvided
method.
The simplest way to use an Informer
is to pass a string to its
apply
method. Given this string, the Informer
will
construct a Report
using the string returned by invoking
nameForReport
, a method defined on Informer
, as the name and
the string passed to apply
as the message
.
The Informer
will then pass the newly created Report
to its wrapped Reporter
via the infoProvided
method.
Here's an example of using an Informer
in a Suite
subclass:
import org.scalatest._ class MySuite extends Suite { def testAddition(info: Informer) { assert(1 + 1 === 2) info("Addition seems to work") } }If you run this
Suite
from the interpreter, you will see the message
included in the printed report:
scala> (new MySuite).execute() Test Starting - MySuite.testAddition(Reporter) Info Provided - MySuite.testAddition(Reporter): Addition seems to work Test Succeeded - MySuite.testAddition(Reporter)Alternatively, you could create a
Report
yourself and pass it to
apply
. You can invoke nameForReport
on the
Informer
to get a user-friendly name to pass to the constructor of
the Report
you create.
The Informer
will then forward the passed Report
to its wrapped Reporter
via the infoProvided
method.
Here's an example of passing your own Report
to an Informer
in a Suite
subclass:
import org.scalatest._ class MySuite extends Suite { def testAddition(info: Informer) { assert(1 + 1 === 2) val myReport = new Report(info.nameForReport, "Here's a stack trace", Some(new Exception), None) info(myReport) } }If you run this
Suite
from the interpreter, you will see the message
included in the printed report:
scala> (new MySuite).execute() Test Starting - MySuite.testAddition(Informer) Info Provided - MySuite.testAddition(Informer): Here's a stack trace java.lang.Exception at line3$object$$iw$$iw$$iw$MySuite.testAddition(:10) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.scalatest.Suite$class.runTest(Suite.scala:1085) at line3$object$$iw$$iw$$iw$MySuite.runTest( :6) ... at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) Test Succeeded - MySuite.testAddition(Informer)
Besides sending a stack trace, you might want to create and pass your own
Report
if you've defined one or more Report
subclasses that
are recognized and handled specially by a Reporter
subclass you've defined.
See the "Extensibility" section in the documentation for Report
for more
information.
Method Summary | |
abstract def
|
apply
(report : Report) : Unit
Provide information in the form of a
Report to be reported to the
wrapped Reporter 's infoProvided method. |
abstract def
|
apply
(message : java.lang.String) : Unit
Provide information in the form of a string message to be reported to the
wrapped
Reporter 's infoProvided method. This method
will create a Report via Report 's auxiliary constructor that takes a
string name and message, using the string returned by invoking
nameForReport as the name and the passed string as the message, and pass
the newly created Report to the wrapped Reporter 's
infoProvided method. |
abstract def
|
nameForReport
: java.lang.String
A name suitable for passing to the constructor of a
Report
when using the apply method that takes a Report .
For example, in an Informer passed to a test method in
trait Suite , this method will return from this method a
user-friendly name for the test (the same name used for the test by Suite
when making testStarting , testSucceeded , etc., reports). |
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 |
Report
to be reported to the
wrapped Reporter
's infoProvided
method.report -
a Report
that encapsulates the event to report.NullPointerException -
if report
reference is null
abstract
def
apply(message : java.lang.String) : Unit
Reporter
's infoProvided
method. This method
will create a Report
via Report
's auxiliary constructor that takes a
string name and message, using the string returned by invoking
nameForReport
as the name and the passed string as the message, and pass
the newly created Report
to the wrapped Reporter
's
infoProvided
method.report -
a Report
that encapsulates the event to report.NullPointerException -
if message
reference is null
abstract
def
nameForReport : java.lang.String
Report
when using the apply
method that takes a Report
.
For example, in an Informer
passed to a test method in
trait Suite
, this method will return from this method a
user-friendly name for the test (the same name used for the test by Suite
when making testStarting
, testSucceeded
, etc., reports).Report
constructor.
ScalaTest 0.9.5
|
|