Code Coverage

Code coverage is a common indicator of code quality. Tools like Sonarqube have metrics on code coverage. Code coverage, in object oriented languages, is calculated on lines of code. But in these languages, there is mainly only one instruction per line of code.

In XSLT, spacing in code is part of code. If we separate two sequence constructors by a space or a carriage return, the output is changed. And so we may have more than one instruction per line of code. Calculating code coverage with XSLT is more complex than with other languages.

XSpec is able to calculate code coverage with XSLT. It requires to use Saxon-EE. XSpec does not provide a numeric result for code coverage, but there is a colored rendering of XSLT code that allows to know if a code instruction is tested or not. Since Saxon 10, API has changed and XSpec framework has not been fully updated for these API changes. Michael Kay (Saxonica) has contributed to XSpec framework to correct this, but there is still some job to do to have good results on code coverage evaluation. If we keep a line scope for coverage, and if we are able to ignore XML vocabulary like namespace declarations, then we can see that all the XSLT code is covered by unit tests.