Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML report does not have condition-coverage attribute for lines with a branch #81

nedbat opened this issue Aug 11, 2010 · 1 comment
bug Something isn't working xml


Copy link

nedbat commented Aug 11, 2010

Originally reported by Kamil Kisiel (Bitbucket: kisielk, GitHub: kisielk)

I'm trying to get branch coverage working with Cobertura plugin for Hudson. However, it appears the XML output from is not complete as the tags which have the branch="true" attribute don't have a condition-coverage to indicate what the coverage level of the branch is.

Apparently this is required by Cobertura (or at least the Hudson plugin) to correctly generate the coverage report for conditionals.

For reference, here's the code from the plugin which looks at branch coverage:

else if ("line".equals(qName)) {
            String hitsString = attributes.getValue("hits");
            String lineNumber = attributes.getValue("number");
            int denominator = 0;
            int numerator = 0;
            if (Boolean.parseBoolean(attributes.getValue("branch"))) {
                final String conditionCoverage = attributes.getValue("condition-coverage");
                if (conditionCoverage != null) {
                    // some cases in the wild have branch = true but no condition-coverage attribute

                    // should be of the format xxx% (yyy/zzz)
                    Matcher matcher = Pattern.compile("(\\d*)\\%\\s*\\((\\d*)/(\\d*)\\)").matcher(conditionCoverage);
                    if (matcher.matches()) {
                        assert matcher.groupCount() == 3;
                        final String numeratorStr =;
                        final String denominatorStr =;
                        try {
                            numerator = Integer.parseInt(numeratorStr);
                            denominator = Integer.parseInt(denominatorStr);
                            rootCoverage.updateMetric(CoverageMetric.CONDITIONAL, Ratio.create(numerator, denominator));
                        } catch (NumberFormatException e) {
                            // ignore

Copy link
Owner Author

nedbat commented Sep 4, 2010

Duplicate of #65.

@nedbat nedbat closed this as completed Sep 4, 2010
@nedbat nedbat added major bug Something isn't working xml labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
bug Something isn't working xml
None yet

No branches or pull requests

1 participant