2 ms·
> So people started writing stupid unit tests for getters and setters in Java DTOs to reach the goal Ideally, the code coverage tool would have heuristics to d
by skissane 3y ago
> So people started writing stupid unit tests for getters and setters in Java DTOs to reach the goal
Ideally, the code coverage tool would have heuristics to detect trivial getter/setter methods, and filter them out, so adding tests for them won't improve code coverage. Non-trivial getters/setters (where there is some actual non-trivial logic involved) shouldn't be filtered, since they should be tested.
Although, there is room for debate about what counts as trivial. Obviously this is trivial:
public void setUser(User user) {
this.user = user;
}
But should this count as trivial too?
public void setUser(User user) {
this.user = Objects.requireNonNull(user);
}
Probably. What about this?
public void setOwners(List<User> owners) {
this.owners = List.copyOf(owners);
}
Probably that too. Which suggests, maybe, there ought to be a configurable list of methods, whose presence is ignored when determining whether a getter/setter is trivial or not.