FLtest: FLtest functions for running simple units tests

Description Usage Arguments Value Author(s) References See Also Examples

Description

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.

Usage

 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"))

Arguments

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

Value

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.

Author(s)

Ernesto Jardim, IPIMAR. FLR Team

References

http://en.wikipedia.org/wiki/Unit_testing

See Also

all.equal, identical, connection

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
	setCon()
	tmpfile <- tempfile()
	zz <- startTest(file=tmpfile)
	tagTest("Testing FLlst testing ...")

	checkTrue(is(FLQuant(), 'FLQuant'))

	finishTest()

	## Not run: 
	# You can now inspect the output by opening tmpfile in your editor
	edit(file=tmpfile)
	
## End(Not run)

FLCore documentation built on May 2, 2019, 5:46 p.m.