Reputation: 2680
I'm working on a spring boot project, i have many Entity classes and DTO classes with mostly getters and setters in it.
is there any way or plugin that create junit test cases for all the Entity and DTO classes. Just to improve test coverage.
currently using this frameworks Spring boot, Hibernate, Junit 4.12, Mockito. Java 1.8, intellij IDE. EX: `
@Entity
@Table(name = "xyz")
public class Xyz {
@Id
@GeneratedValue(strategy = IDENTITY)
public Integer id;
@Column(name = "col1")
public Integer col1;
@Column(name = "col2")
public Integer co2;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
};`
Upvotes: 1
Views: 17458
Reputation: 593
For test case coverage you can do it like below , But I don't think so its good way, But it helps to increase code coverage:
public class XyzTest {
public Xyz crateTestSuite(){
return new Xyz();
}
@Test
public void testGetId() {
Integer id= 0;
Xyz xyz =null;
xyz = crateTestSuite();
id = xyz.getId()
}
@Test
public void setId(Integer id) {
Integer id= 0;
Xyz xyz =null;
xyz = crateTestSuite();
xyz.setId(id)
}
}
Upvotes: 0
Reputation: 6114
Never ever write tests for entities and DTOs. Usually They do not have any business logic you could test (unless something is really wrong with your design).
Better to exclude them from your test metrics than trying to make tests for making tests.
Upvotes: 7