Skip to content

Ignore switch case default cases which can't be covered #1211

@Hollerweger

Description

@Hollerweger

Scenario

  • JaCoCo version: (from right bottom corner of JaCoCo report)
    • 0.8.6
  • Operating system:
    • Windows
  • Tool integration: Maven / Ant / CLI / API
    • Maven
  • Description of your use case:

Java Switch default cased can't be convered if all other cases are covered:

switch (enum) {
	case CASE_1:
		doSomething();
		break;
	case CASE_2:
		doSomethingElse();
		break;
	default:
               //Throw Exception in case a new Enum value is added in future and not yet supported
               throw new UnsupportedOperationException("Not supported enum: " + enum.getName());
}

Jacoco should add an option to ignore/mark switch default cases as covered.

Current Behaviour

Switch default cases are makred as uncovered in case all other cases are covered even if coverage is not possible.

Wanted Behaviour

Jacoco should add an option to ignore/mark switch default cases as covered.
If possible Jacoco can check if all other cases are covered first, if not then a simple config option would be enough.

Possible Workarounds

Add unwanted Enums like UNKOWN or DEFAULT and try to cover default case with them.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Awaiting triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions