3 ms·
I've had a similar debate. Someone kept trying to exclude some of our data objects from test coverage reports. I agreed we shouldn't bother testing getter/set
by taeric 9y ago
I've had a similar debate. Someone kept trying to exclude some of our data objects from test coverage reports. I agreed we shouldn't bother testing getter/setters. But, those object better be used in other tests we are writing.
- pleasecalllater 9y agoAs usually: it depends. Sometimes testing getters/setters is a good thing.
- taeric 9y agoMy point is when we checked the report, the file was already getting covered. If your tests of the system aren't using the data objects of your system, you have larger problems.
- JustSomeNobody 9y agoThe typical argument for getters/setters is that there is some logic that should be performed and that's why the fields should not be public. If there's logic, they should be tested. If there's no logic, they should be public fields.
- taeric 9y agoSee my sibling response. The files were tested. There just wasn't a "testGetter" method in our tests.
- twblalock 9y agoNo, the point of getters and setters is that the interface to get and set fields should be the same whether or not logic is being performed behind the scenes, and the caller should not need to know. Making fields public makes it impossible to add logic in the future without changing other code. That breaks encapsulation and is generally non-idiomatic in languages with getters and setters.