runTestSuite is the central function of the RUnit package.
Given one or more test suites it identifies and sources specified test
code files one after another and executes all specified test functions
defined therein. This is done sequentially for suites, test code files
and test functions. During the execution information about the test function calls including the
possible occurence of failures or errors is recorded and returned at the
end of the test run. The return object can then be used to create a
test protocol of various formats. runTestFile is just a convenience function for executing the
tests in a single test file.
defineTestSuite is a helper function to define a test
suite. See below for a precise definition of a test suite.
isValidTestSuite checks if an object defines a valid test suite.
defineTestSuite(name, dirs, testFileRegexp="^runit.+\.[rR]$", testFuncRegexp="^test.+", rngKind="Marsaglia-Multicarry", rngNormalKind="Kinderman-Ramage")
isValidTestSuite(testSuite)
runTestSuite(testSuites, useOwnErrorHandler=TRUE)
runTestFile(absFileName, useOwnErrorHandler=TRUE, testFuncRegexp="^test.+", rngKind="Marsaglia-Multicarry", rngNormalKind="Kinderman-Ramage")RNGkind).RNGkind).TRUE the RUnit framework installs
its own error handler during test case execution (but reinstalls the
original handler before it returns). If FALSE the error
handler is not touched by RUnit but then the test protorunTestSuite and runTestFile both return an object of
class RUnitTestData. defineTestSuite returns an object of class RUnitTestSuite.
The specification which functions are taken as test functions is
contained in an object of class RUnitTestSuite which is a list
with the following elements.
[object Object],[object Object],[object Object],[object Object]
After the RUnit framework has sequentially executed all test suites it returns all
data collected during the test run as an object of class
RUnitTestData. This is a (deeply nested)
list with one list element for each executed test suite. Each of these
executed test suite lists contains the following elements:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The sourceFileResults list just mentioned contains one element
for each specified test function in the source file. This elemnt is a list with
the following entries:
[object Object],[object Object],[object Object],[object Object]
To further control test case execution it is possible to define two
parameterless function .setUp() and .tearDown() in each
test file. .setUp() is executed directly before and
.tearDown() directly after each test function execution.
Quite often, it is useful to base test cases on random numbers. To
make this procedure reproducible, the function runTestSuite
sets the random number generator to the default setting
RNGkind(kind="Marsaglia-Multicarry",
normal.kind="Kinderman-Ramage") before sourcing each test file
(note that this default has been chosen due to historical reasons and
differs from the current R default). This default can be overwritten
by configuring the random number generator at the beginning of a test
file. This setting, however, is valid only inside its own source file
and gets overwritten when the next test file is sourced.
checkTrue and friends for writing test cases.
printTextProtocol and printHTMLProtocol for printing the test protocol.## run some test suite
myTestSuite <- defineTestSuite("RUnit Example", system.file("examples", package="RUnit"), testFileRegexp="correctTestCase.r")
testResult <- runTestSuite(myTestSuite)
## prints detailed text protocol
## to standard out:
printTextProtocol(testResult, showDetails=TRUE)
## for single test files, e.g. outside a package context
testResult2 <- runTestFile(file.path(system.file("examples", package="RUnit"), "correctTestCase.r"))
printTextProtocol(testResult2, showDetails=TRUE)Run the code above in your browser using DataLab