[英]Need to ignore Lombok Generated Code for JaCoCo while it keeps testing Comparable - How to do?
There are many articles here about that instructing to use lombok.config
file inside your project root and add these entries in it:这里有很多关于指示在项目根目录中使用
lombok.config
文件并在其中添加这些条目的文章:
lombok.addLombokGeneratedAnnotation = true
But my issue is slightly different.但我的问题略有不同。 The class that has Lombok annotations also implements Comparable and then the method compareTo.
具有 Lombok 注释的 class 也实现了 Comparable,然后实现了方法 compareTo。
@Document(collection = "item")
@Data
@Builder
public class Item implements Serializable, Comparable<Item> {
@JsonIgnore
private static final long serialVersionUID = 5816882082047405354L;
@Id
@JsonProperty
private String id;
@JsonProperty
private String nome;
@JsonProperty
private Double valor;
public int compareTo(Item o) {
int retorno = this.nome.compareToIgnoreCase(o.getNome());
if (retorno == 0) {
if (this.getValor() < o.getValor()) {
retorno = -1;
} else if (this.getValor() > o.getValor()) {
retorno = 1;
}
}
return retorno;
}
}
And this is my test class.这是我的测试 class。
public class TestItem {
@Test
public void shouldCompareFullAndBeEqual() {
final Item item1 = Item.builder().nome("Item").valor(20.0).build();
item1.setId("IDDCLIP");
final Item item2 = Item.builder().nome("Item").valor(20.0).build();
item2.setId("IDDCLIP");
assertEquals(item1.compareTo(item2), item2.compareTo(item1));
}
@Test
public void shouldCompareAndBeDifferentByValue() {
final Item item1 = Item.builder().nome("Item").valor(30.0).build();
item1.setId("IDDCLIP");
final Item item2 = Item.builder().nome("Item").valor(20.0).build();
item2.setId("IDDCLIP");
assertNotEquals(item1.compareTo(item2), item2.compareTo(item1));
}
@Test
public void shouldCompareAndBeDifferentByVName() {
final Item item1 = Item.builder().nome("Item1").valor(20.0).build();
item1.setId("IDDCLIP");
final Item item2 = Item.builder().nome("Item").valor(20.0).build();
item2.setId("IDDCLIP");
assertNotEquals(item1.compareTo(item2), item2.compareTo(item1));
}
@Test
public void shouldCompareAndBeDifferentByNameAndValue() {
final Item item1 = Item.builder().nome("Item1").valor(30.0).build();
item1.setId("IDDCLIP");
final Item item2 = Item.builder().nome("Item").valor(20.0).build();
item2.setId("IDDCLIP");
assertNotEquals(item1.compareTo(item2), item2.compareTo(item1));
}
}
When I run my Unit Tests over this class although it tests the compareTo()
it does not appears on my code coverage report as covered.当我在此 class 上运行单元测试时,尽管它测试了
compareTo()
,但它并没有出现在我的代码覆盖率报告中。
@EqualsAndHashCode.Exclude
, while your code does not.@EqualsAndHashCode.Exclude
,而您的代码没有。 Who knows what other things are different in your setup?@Generated
annotation, and hence your lombok.config
file, should have no influence on the details of coverage. @Generated
注释以及您的lombok.config
文件应该不会影响覆盖的细节。 I would expect either no coverage data at all or full. I managed to solve the problem.我设法解决了这个问题。 The @Test annotation was wrong.
@Test 注释是错误的。 I was using a wrong package.
我使用了错误的 package。 After that and a mvn clean the coverage became 100%
之后,mvn clean 覆盖率变为 100%
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.