Search code examples
ballerinaballerina-swan-lake

How to exclude a module from test coverage calculations for a Ballerina package?


I have a Ballerina package with multiple modules, and one of them consists mostly of autogenerated code for which I currently do not have tests.

When I generate test coverage report, the overall coverage percentage is heavily impacted by the absence of tests for that particular module. Is there a method or configuration to exclude this module from the overall test coverage calculations?


Solution

  • You can simply exclude generated sources from coverage as follows,

    bal test --test-report --code-coverage --coverage-format=xml --excludes='./generated'
    

    If you want to exclude a single Ballerina source file from coverage you can pass the file path with excludes flag. You can also use glob patterns to exclude different set of source files.

    For more info refer https://ballerina.io/learn/test-ballerina-code/execute-tests/#generate-test-report-and-code-coverage