Learn R Programming

RUnit (version 0.4.30)

runTestSuite: Definition and execution of RUnit test suites.

Description

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 occurrence 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.

Usage

defineTestSuite(name, dirs, testFileRegexp = "^runit.+\\.[rR]$",
                testFuncRegexp = "^test.+",
                rngKind = "Marsaglia-Multicarry",
                rngNormalKind = "Kinderman-Ramage")
isValidTestSuite(testSuite)
runTestSuite(testSuites, useOwnErrorHandler = TRUE, 
             verbose = getOption("RUnit")$verbose)
runTestFile(absFileName, useOwnErrorHandler = TRUE,
            testFuncRegexp = "^test.+",
            rngKind = "Marsaglia-Multicarry",
            rngNormalKind = "Kinderman-Ramage", 
            verbose = getOption("RUnit")$verbose)

Arguments

name
The name of the test suite.
dirs
Vector of absolute directory names where to look for test files.
testFileRegexp
Regular expression for matching test files.
testFuncRegexp
Regular expression for matching test functions.
rngKind
name of an available RNG (see RNGkind for possible options).
rngNormalKind
name of a valid rnorm RNG version (see RNGkind for possible options).
testSuite
A single object of class test suite.
testSuites
A single object of class test suite or a list of test suite objects.
useOwnErrorHandler
If 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 proto
verbose
level of verbosity of output log messages, 0: omits begin/end comments for each test function. Queried from global options set for RUnit at package load.
absFileName
Absolute file name of a test function.

Value

  • runTestSuite and runTestFile both return an object of class RUnitTestData.

    defineTestSuite returns an object of class RUnitTestSuite.

encoding

latin1

concept

  • test suite
  • test runner
  • RUnit

code

RNGkind(kind="Marsaglia-Multicarry", normal.kind="Kinderman-Ramage")

describe

  • kindCharacter string with one of success, error or failure describing the outcome of the test function.
  • msgthe error message in case of an error or failure and NULL for a successfully executed test function.
  • timeThe duration (measured in seconds) of the successful execution of a test function and NULL in the case of an error or failure.
  • traceBackThe full trace back as a character vector in the case of an error and NULL otherwise.

Details

The basic idea of the RUnit test framework is to declare a certain set of functions to be test functions and report the results of their execution. The test functions must not take any parameter nor return anything such that their execution can be automatised.

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]

See Also

checkTrue and friends for writing test cases. printTextProtocol and printHTMLProtocol for printing the test protocol. See RUnit-options for global options controlling log out.

Examples

Run this code
## run some test suite
myTestSuite <- defineTestSuite("RUnit Example",
                               system.file("examples", package = "RUnit"),
                               testFileRegexp = "correctTestCase.r")
testResult <- runTestSuite(myTestSuite)

##  same but without the logger being involved
## source(file.path(system.file("examples", package = "RUnit"), 
##                  "correctTestCase.r"))
## test.correctTestCase()


## prints detailed text protocol
## to standard out:
printTextProtocol(testResult, showDetails = TRUE)

##  use current default RNGs
myTestSuite1 <- defineTestSuite("RUnit Example",
                               system.file("examples", package = "RUnit"),
                               testFileRegexp = "correctTestCase.r",
                               rngKind = "Mersenne-Twister",
                               rngNormalKind = "Inversion")

testResult1 <- runTestSuite(myTestSuite)


##  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