Description Usage Arguments Value Author(s) References See Also Examples
A set of functions is provided to create and run simple unit tests. The basic functions
provided allow checking whether two objects are identical (checkIdentical
),
equal (checkEqual
), if a expression is TRUE
(checkTrue
)
or FALSE
(checkFalse
), and if a piece of code fails (checkFail
)
or runs (checkRun
).
Output of all tests is directed to a file or connection, specified by a call to
setCon()
to set the connection, and then to startTest
to specify the
file to output to. At the end of the test the connection needs to be closed by using
finishTest
.
Tests can be labelled with a text message for easier reading by using tagTest
.
Be warned that when any of these checks fails, failure is reported accordingly, but the
test run will not be stopped. i.e. R CMD check
will successfully finish. Test
reports should be inspected after running them to ensure problems are detected and
corrected.
1 2 3 4 5 6 7 8 9 10 | setCon(con='zz')
startTest(file="testReport.txt")
finishTest(con=getOption("con"))
tagTest(tag="My tag is better than yours !", con=getOption("con"))
checkIdentical(x, y, con=getOption("con"))
checkEqual(x, y, con=getOption("con"), tolerance =.Machine$double.eps^0.5, ...)
checkTrue(x, con=getOption("con"))
checkFalse(x, con=getOption("con"))
checkFail(x, con=getOption("con"))
checkRun(x, con=getOption("con"))
|
x, y |
Objects to compare or expression to run |
file |
File to direct output report to |
con |
Option for connection |
tag |
Text to label the test output file |
tolerance |
Allowed difference between two values in a comparison |
... |
Extra arguments to be passed on to all.equal |
Output is directed to the file specified, so no objects are created in the workspace
by the check functions. A connection
is created by startTest
but is
subsequently closed by finishTest
.
Ernesto Jardim, IPIMAR. FLR Team
http://en.wikipedia.org/wiki/Unit_testing
all.equal
, identical
, connection
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.