8 Running test cases

Using package wyz.code.offensiveProgramming, you have the opportunity to define test cases and to embed them in your class definition, to ease retrieval and reuse.

Doing so, allows to get following benefits

  1. discover defined test case definitions
  2. run of any test case definition
  3. get interactively the R code of a test case, allowing you to play with it, manually, when needed
  4. get contextual results from the test case runs

8.1 Embedding test cases

Embedding test cases in class definition is accomplished by declaring a variable named testCaseDefinitions, and providing its content, that is a data.table. Content could be partial or complete depending of your goals. Spectrum of provided tests cases is as you desire it to be, as shallow or deep as needed.

The data.table must hold following columns and content

  1. function_name, a vector of strings, each being the name of the function to test,
  2. standard_evaluation, a vector of strings, where values are taken from set {‘correct’, ‘erroneous’, ‘failure’}
  3. type_checking_enforcement, a vector of strings, where values are taken from set {‘correct’, ‘erroneous’, ‘failure’}
  4. test case definitions, that is a list of TestCaseDefinition objects.

Correct implies right type and right result. Erroneous implies right type and wrong result. Failure implies wrong type. To get more details about syntax, please refer to manual page of TestCaseDefinition.

8.2 Discovering test cases

The considered R object has to be instrumented with test case definitions.

8.2.1 Test case verifications

To verify test cases definitions use function verifyTestCaseDefinitions.

Here, the validity flag is TRUE and checks have been done against full instrumentation, meaning each function of the object must own at least one associated test case.

If this does not match your need, specify requiresFullInstrumentation_b_1 = FALSE as parameter to the call.

8.2.3 Getting test cases descriptions

Use function retrieveTestCaseDescriptions to get access to recorded test case descriptions.

Getting test case description for function divideByZero, can be achieved with a sequence like

Of course, no obligation to restrict output to a single function as in this example.

Do not be fooled, description is text not code as you could deduce from previous example. See below.

8.3 Running test cases

8.3.1 Run a single test case

I want to run the test number 4 of object AdditionTCFIG1. Let’s first, know more about it.

To run the chosen test case, use function runTestCase.

Result has two parts. A raw part, that holds the intermediate computation results, and a synthesis part, that is the only one shown above.

Here, the status flag is TRUE meaning test case behaves perfectly in accordance with declared semantic names, under provided values.

8.3.2 Run several test cases

You can provide a vector instead of a single test number if you want to run several use test cases in one call.

Test 14 fails under chosen evaluation mode, and therefore requires a fix.

Here looking at raw results will provide root causes of failure. Provided values are double, whereas integers were expected. To understand the full details, you will have to run this example and to print rtc globally to get access to many details far too long to be displayed here.