View source: R/module_testing.R
test_module | R Documentation |
Modules can be tested using test cases, which are sets of known outputs that correspond to particular inputs. The functions here provide ways to create test cases and test modules.
test_module
runs one test case for a module, returning an error message
if its output does not match the expected value.
case
helps define test cases for module testing by combining the
required elements into a list with the correct names as required by
test_module
.
cases_from_csv
helps define test cases for module testing by creating a
list of test cases from a csv
file.
test_module(module_name, case_to_test)
case(inputs, expected_outputs, description)
cases_from_csv(module_name, directory)
module_name |
A string specifying one BioCro module, formatted like
|
case_to_test |
A list with three named elements that describe a module test case:
|
inputs |
See the corresponding entry in |
expected_outputs |
See the corresponding entry in |
description |
See the corresponding entry in |
directory |
The directory where module test case files are stored, e.g.
|
The test_module
function forms the basis for the BioCro module testing
system. (See module_testing
for more information.) The functions
case
and cases_from_csv
are complementary to test_module
because they help to pass suitably-formatted test cases to test_module
.
test_module |
If the test passes, an empty string; otherwise, an informative message about what went wrong. |
case |
A list with three named elements ( |
cases_from_csv |
A list of test cases created by the |
modules
module_case_files
module_paste
module_testing
test_module_library
# Example 1: Defining an individual test case for the 'BioCro' module library's
# 'thermal_time_linear' module and running the test. This test will pass, so the
# return value will be an empty string: `character(0)`
test_module(
'BioCro:thermal_time_linear',
case(
list(time = 101, sowing_time = 100, tbase = 20, temp = 44),
list(TTc = 1.0),
'temp above tbase'
)
)
# Example 2: Defining an individual test case for the 'BioCro' module library's
# 'thermal_time_linear' module and running the test. This test will fail, so the
# return value will be a message indicating the failure.
test_module(
'BioCro:thermal_time_linear',
case(
list(time = 101, sowing_time = 100, tbase = 20, temp = 44),
list(TTc = 2.0),
'temp above tbase'
)
)
# Example 3: Loading a set of test cases from a file and running one of them.
# Note: here we use the `initialize_csv` function first to ensure that there is
# a properly defined test file in a temporary directory.
td <- tempdir()
module_name <- 'BioCro:thermal_time_linear'
initialize_csv(module_name, td)
cases <- cases_from_csv(module_name, td)
test_module(module_name, cases[[1]])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.