I was doing some junit testing in my codebase and found that Intellij is marking all my simple Record classes as 0% covered
I have a simple record that looks like this :
public record ProcessRequestDTO(String path) {
// NOTHING HERE
}
My question is, what do Intellij coverage expect me to cover here ? Constructor ? Getters/Setters ? if the latters are true, why is non-record classes annotated with @Getter, @Setter, @AllArgsConstrusctor are not even detected as to be covered ? (see next code)
I can't use jacoco right now so I'm expecting an answer for the default Intellij coverage tool.
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Other{
private File file;
}
// This class is not even added to the coverage pool
Edit, as this subject is not clear, I add this images which represents classes marked as 'nothing to cover' and classes marked as "potential for coverage here"

TLDR; When running jacoco, it seems that you need to call constructor and getters in order to get record declaration covered. I suspect IntelliJ expects the same, since both rely on bytecode instrumentation.
I created a simple record:
public record Foo (String bar) {}
Then created a test case where I called both constructor and getter:
assertThat(new Foo("Test").test()).isEqualTo("Test");
Then I run tests with mvn and jacoco-maven-plugin:0.8.11:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test org.jacoco:jacoco-maven-plugin:report
Then I opened the results with Run - Show Coverage Data... and chose generated jacoco.exec file. It shows the Foo class covered 100%.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With