At test execution time, Gherkin offers the option Enable coverage at the top left of the test results. Enabling the option reruns the tests and then lists the files that were tested at the bottom of the page.
Gherkin calculates code coverage for any JavaScript file that is loaded after the test harness. This may cause some system libraries to appear in the results. You can specify which files to calculate code coverage for by adding code to your HTML bootstrap file (after loading SAPUI5, but before running your tests), as follows.
Code coverage with Istanbul
relies on a UI5 server and UI5
Middleware Code Coverage.
If you use UI5 Tooling's ui5
serve
, you would need to enable it in ui5.yaml
and package.json
of your project.
<script src="path/to/resources/sap/ui/qunit/qunit-coverage-istanbul.js" data-sap-ui-cover-only="GherkinWithOPA5/" data-sap-ui-cover-never="sap/ui/"> </script>
For more information, see the documentation.
Blanket.js
offers code coverage and instrumentation for JavaScript up to ECMAScript Language Specification 5. As of SAPUI5 version 1.113.0, code coverage measurement via Istanbul
is the recommended option.
<script src="../../resources/sap/ui/qunit/qunit-coverage.js" data-sap-ui-cover-only="GherkinWithOPA5/" data-sap-ui-cover-never="sap/ui/"> </script>
For more information, see the documentation for Blanket.js
on GitHub. Keep in mind that the attribute name is slightly
different in the SAPUI5 implementation
(data-sap-ui-cover-only
instead of data-cover-only
).