runTestSuite(RUnit)
runTestSuite()所属R语言包:RUnit
Definition and execution of RUnit test suites.
定义和执行鲁尼特测试套件。
译者:生物统计家园网 机器人LoveR
描述----------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.
runTestSuite是的鲁尼特包的核心功能。由于一个或多个测试套件,它标识和指定的源测试代码文件一个又一个执行指定的所有测试功能,其中定义。这是按顺序进行的套房,测试代码文件和测试功能。的执行过程中的有关测试的函数调用,包括可能发生的故障或错误的信息被记录在测试运行结束并返回。返回的对象,然后,可以使用各种不同的格式来创建一个测试协议。
runTestFile is just a convenience function for executing the tests in a single test file.
runTestFile仅仅是一个方便的功能,在一个单一的测试文件执行测试。
defineTestSuite is a helper function to define a test suite. See below for a precise definition of a test suite.
defineTestSuite是一个辅助函数来定义一个测试套件。请参阅下面的精确定义的测试套件。
isValidTestSuite checks if an object defines a valid test suite.
isValidTestSuite检查,如果一个对象定义了一个有效的测试套件。
用法----------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).
名称可用的RNG(见RNGkind可能的选择)。
参数:rngNormalKind
name of a valid rnorm RNG version (see RNGkind for possible options).
一个的有效准化RNG版本的名称(见RNGkind可能的选择)。
参数: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 protocol does not contain any call stacks in the case of errors.
如果TRUE鲁尼特框架安装自己的错误处理函数在测试用例执行(但重新安装原始的处理程序在返回之前)。如果FALSE的错误处理程序未触及鲁尼特但测试协议不包含任何错误的情况下,调用堆栈。
参数: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.
水平冗长的输出log消息,0:忽略了每个测试函数的开始/结束注释。从全局选项设置为鲁尼特包加载质疑。
参数:absFileName
Absolute file name of a test function.
绝对文件名的测试功能。
Details
详细信息----------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.
runit的测试框架的基本思路是,申报一组特定的功能,功能测试和报告其执行的结果。测试功能,不得采取任何参数,也不返回任何东西,他们可以执行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.
测试功能的功能被作为本说明书中包含的类RUnitTestSuite,这是一个包含下列元素的列表的一个目的。
nameA simple character string. The name of a test suite is mainly used to create a well structure test protocol.
NAMEA简单的字符串。一个测试套件的名称,主要用于创造一个良好的结构测试协议。
dirsA character vector containing the absolute names of all directories where to look for test files.
dirsA字符向量的所有目录到哪里寻找测试文件的绝对名称。
testFileRegexpA regular expression specifying the test files. All files in the test directories whose names match this regular expression are taken as test files. Order of file names will be alphabetical but depending on the used locale.
testFileRegexpA正则表达式指定的测试文件。测试目录中的所有文件,其名称与该正则表达式匹配的测试文件。文件名的顺序是按字母顺序排列的,但根据所使用的语言环境。
testFuncRegexpA regular expression specifying the test functions. All functions defined in the test files whose names match this regular expression are used as test functions. Order of test functions will be alphabetical.
testFuncRegexpA正则表达式指定的测试功能。这个正则表达式匹配的测试文件,其名称中定义的所有功能作为测试功能。测试功能的顺序是按字母顺序排列的。
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:
后鲁尼特框架顺序执行所有测试套件,它作为一个对象类RUnitTestData试运行期间收集的所有数据返回。这是一个深层嵌套的一个列表中的元素的列表,每一个执行的测试套件。执行这些测试套件列表包含以下元素:
nTestFuncThe number of test functions executed in the test suite.
nTestFuncThe在测试套件的测试执行的功能数量。
nErrThe number of errors that occurred during the execution.
nErrThe执行过程中发生的错误。
nFailThe number of failures that occurred during the execution.
nFailThe执行过程中发生的故障数。
dirsThe test directories of the test suite.
目录测试套件dirsThe测试。
testFileRegexpThe regular expression for identifying the test files of the test suite.
testFileRegexpThe正则表达式识别的测试套件的测试文件。
testFuncRegexpThe regular expression for identifying the test functions of the test suite.
testFuncRegexpThe正则表达式识别功能的测试套件的测试。
sourceFileResultsA list containing the results for each separate test file of the test suite.
sourceFileResultsA列表,其中包含的测试套件为每个单独的测试文件的结果。
The sourceFileResults list just mentioned contains one element for each specified test function in the source file. This element is a list with the following entries:
sourceFileResults刚才提到的列表包含每一个指定的测试功能在源文件中的一个元素。此元素是一个表具有以下条目:
kindCharacter string with one of success, error or failure describing the outcome of the test function.
kindCharacter字符串之一success,error或failure描述结果的测试功能。
msgthe error message in case of an error or failure and NULL for a successfully executed test function.
msgthe错误信息的错误或失败的情况下和NULL的成功执行的测试功能。
timeThe duration (measured in seconds) of the successful execution of a test function and NULL in the case of an error or failure.
伊诺持续时间(以秒为单位)的成功执行的测试功能和NULL错误或失败的情况下。
traceBackThe full trace back as a character vector in the case of an error and NULL otherwise.
作为一个字符向量的情况下,错误和NULL否则traceBackThe完整的回溯。
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.
为了进一步控制测试用例的执行,它可以定义两个参数的函数.setUp和.tearDown在每个测试文件。 .setUp()执行之前,直接和.tearDown()后直接执行每个测试函数。
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.
经常,这是很有用的随机数的基本测试例。为了使此过程可重复的功能runTestSuite设置随机数生成器的默认设置RNGkind(kind="Marsaglia-Multicarry", normal.kind="Kinderman-Ramage")之前采购的每个测试文件(注意,此默认已经选择由于历史的原因,不同的电流R默认情况下)。可以覆盖此默认配置的随机数生成器的一个测试文件开始。然而,这样设置后,只在其自己的源文件是有效的,被覆盖时,下一个测试文件的时候。
值----------Value----------
runTestSuite and runTestFile both return an object of class RUnitTestData.
runTestSuite和runTestFile返回一个对象类RUnitTestData。
defineTestSuite returns an object of class RUnitTestSuite.
defineTestSuite返回一个对象类RUnitTestSuite。
(作者)----------Author(s)----------
Thomas K枚nig, Klaus J眉nemann
& Matthias Burger
参见----------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.
checkTrue和编写测试用例的朋友。 printTextProtocol和printHTMLProtocol用于打印测试协议。请参阅鲁尼特选项全局选项控制的退出。
实例----------Examples----------
## 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"), [#源(file.path(。系统(“例子”,包=“鲁尼特”),]
## "correctTestCase.r"))[#“correctTestCase.r”))]
## test.correctTestCase()[:#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)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|