Code coverage and reporting
The Ballerina Test Framework allows you to generate test reports and code coverage reports for the executed tests.
Generate a test report
By default, a summary of the test statuses is printed in the console at the end of the test execution.
In addition to the results printed in the console, an HTML test report can be generated by passing the
--test-report flag in the Ballerina command. The link to the file will be printed in the console at the end of the test execution.
The test report contains the total passed, failed, and skipped tests of the entire package and of the individual modules.
$ bal test --test-report
A sample view of the test report is shown below.
Generate a code coverage report
The Ballerina test framework provides an option to analyze the code coverage of a standard Ballerina package. This feature provides details about the coverage of the program source code by the tests executed.
You can pass the
--code-coverage flag along with the
--test-report flag in the test execution command and
generate the code coverage report at the end of the test execution. The generated file is an extended version of the
In addition to the test results, this file would contain details about the source code coverage at different levels.
- Package-level coverage as an average
- Module-level coverage as an average
- Individual source file coverage
The code coverage only includes the Ballerina source files being tested and not any files under the
$ bal test --test-report --code-coverage
A sample view of the code coverage report is shown below.
Generate a JaCoCo XML report
You can pass the
--coverage-format=xml flag along with the
--code-coverage flag in the test execution command and
generate the JaCoCo XML report at the end of the test execution.
This file can be uploaded to the CI/CD tools (e.g., CodeCov) to display the coverage information for both Ballerina and
the native Java sources used within a Ballerina package.