dylanb / gulp-coverage

Gulp coverage reporting for Node.js that is independent of the test runner
MIT License
60 stars 12 forks source link

condition coverage #37

Open zhouyulin opened 9 years ago

zhouyulin commented 9 years ago

I want to get the condition coverage report, it seems that only line coverage can be reported.

dylanb commented 9 years ago

I think what you are looking for is what I refer to as "statement coverage". This is reported by the tool along with chainable coverage - which is an expanded form of branch coverage because it covers tracking chained calls that do not have any effect (e.g. they pass in empty lists and they call code that is in a library and therefore has no coverage tracking).

Look at the example report and you will see that some of the conditions in the if statement and the ternary are shown as not being covered.

zhouyulin commented 9 years ago

Thank you so much for responding so quickly.
Statement coverage which you say it should be the C1 coverage(branch coverage). But I want to get the C2 coverage .(http://www.slideshare.net/hiroppie/test-coverage) If this tool support C2 coverage , could you tell me how to set the option command?

dylanb commented 9 years ago

Here is a module that has the four different conditions

module.exports = function () {
    var a = false, b = false;

    if (a && b) {
        console.log('a && b');
    }

    a = true;

    if (a && b) {
        console.log('a && b');
    }

    b = true;
    a = false;

    if (a && b) {
        console.log('a && b');
    }

    a = true;
    b = true;

    if (a && b) {
        console.log('a && b');
    }
};

If I run the coverage report on that, I get the following:

image

As you can see, it shows exactly which of the elements of the if statement were executed. It also shows how many times each statement was executed, what it does not show is when each condition did pass, but not every pass through the if statement evaluated to true, whether some of the failures were due only to the second condition failing, or whether they were all due to the first failing.

So it comes close, but no cigar.