Skip to content

Code Coverage

Daniel Silhavy edited this page Dec 5, 2022 · 1 revision

With version 2.0.0 of the Conformance Tools we introduced the required functionality for deriving the code coverage for a whole set of testvectors.

The starting point for deriving the code coverage for one or multiple test vectors is phpunit.functional-coverage.xml in the root folder of the project. It defines the required parameters for running phpunit with code coverage support.

Step 1: Defining the test folder

The Conformance tools ship with predefined configurations for deriving the code coverage of the DASH-IF and CTA-WAVE database. The target test folder can be specified in the <testsuites> field. In the example below it links to the CTA-WAVE folder:

<testsuites>
    <testsuite name="default">
        <directory>functional-tests/cta</directory>
    </testsuite>
</testsuites>

Step 2: Defining the output folder

The code coverage results are written to a target folder in xml and html format. The target folders can be defined in the <report> element:

<report>
    <html outputDirectory="functional-test-results/html-reports-functional-tests" lowUpperBound="50" highLowerBound="90"/>
    <xml outputDirectory="functional-test-results/xml-reports-functional-tests" lowUpperBound="50" highLowerBound="90"/>
</report>

Step 3: Defining the test vectors

The functionalTest.php file is the entry point for the test suite. It defines a function streamProvider() that reads and parses JSON representation of the respective testvector database and supports blacklisting of specific testvectors. The testThis() function uses the output of the streamProvider() function and performs the conformance validation for each of the provided test vectors.

The JSON file that the streamProvider() function uses can be defined directly in the function itself:

$content = file_get_contents("functional-tests/cta/wave.json");

Step 4: Running the code coverage

The code coverage script can be executed directly from the terminal:

/bin/php phpunit --configuration phpunit.functional-coverage.xml

Step 5: Checking the output

By default, the output files are located in the functional-test-results folder. The html output should look the following:

code-coverage