Reputation: 11
How can I write the test cases for Lombok annotation?
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ABC{
private String status;
private String errorCode;
private String message;
private String id;
private Long orderNumber;
private Long lineId;
}
//writing testcases for above class
@Test
public void testupdate_1()throws Exception{
ABC result=new ABC();
result.setStatus("");
result.setErrorCode("");
result.setMessage("");
result.setId("");
result.setOrderNumber(123l);
result.setLineId(12l);;
assertNotNull(result);
assertEquals("", result.getStatus());
assertEquals("", result.getErrorCode());
assertEquals("", result.getMessage());
assertEquals("", result.getId());
assertEquals(Long.valueOf(123l), result.getOrderNumber());
assertEquals(Long.valueOf(12l), result.getLineId());
}
even I tried this but code coverage is showing very less. Please, anyone can help me to find correct answer for this.
Upvotes: 1
Views: 577
Reputation: 1069
You are testing only all args constructor. You can add test for no args constructor like:
@Test
public void testABC() {
ABC abc = new ABC();
assertNotNull(abc);
}
Upvotes: 1
Reputation: 102902
Lombok author here: You don't.
You don't write test code to test that the inner workings of hibernate work correctly either; it's hibernate's job to test that. You don't test whether java's switch
statement does what the spec says it does; it's team OpenJDK (the authors of javac
)'s job to test that.
If you're chasing 100% code coverage by your tests, configure your code coverage tool to exclude lombok-generated code.
Upvotes: 4