Skip to content

Misleading Line Coverage Calculation for @DoNotMutate Methods #1374

@see-quick

Description

@see-quick

This issue arises from methods annotated with @DoNotMutate (those methods, which are typically impossible to test on the UNIT level). These methods are excluded from mutation testing but still contribute to the line coverage calculation. The line coverage suggests insufficient testing, even though these methods are exercised through integration tests.

Expected Behavior:

For methods annotated with @DoNotMutate:

  • Line coverage should not penalize the overall coverage score.
  • Either exclude these methods entirely from line coverage calculations or treat them as fully covered when integration tests exercise the related system behaviour.

Current Behavior:

The @DoNotMutate annotation ensures mutation coverage is 100%, but line coverage remains low because:

  • Integration tests do not map directly to specific lines within the annotated methods.
  • The framework still includes these methods in line coverage calculations.

Example:

package io.example;

import com.groupcdg.pitest.annotations.DoNotMutate;

public class Example1 {

    public String methodCoveredByTests() {
        return "This method is covered by tests.";
    }

    @DoNotMutate
    public String methodNotCoveredByTests() {
        return "This method is NOT covered by tests.";
    }
}

The mutation coverage would be 100% but line coverage is 50% which I think it not What is the aim of it? Am I somehow mistaken? Thanks for your answer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions