There is a well-known debate in Java (and other communities, I'm sure) whether or not trivial getter/setter methods should be tested. Usually, this is with respect to code coverage. Let's agree that this is an open debate, and not try to answer it here.
There have been several blog posts on using Java reflection to auto-test such methods.
Does any framework (e.g. jUnit) provide such a feature? e.g. An annotation that says "this test T should auto-test all the getters/setters on class C, because I assert that they are standard".
It seems to me that it would add value, and if it were configurable, the 'debate' would be left as an option to the user.
Unit tests are there to test the behaviour of your code, in an expressive and meaningful way, and getters/setters are only a means to an end. If you tests use the getters/setters to achieve their goal of testing the "real" functionality, then that's good enough.
Automated is generally the preferred method as it saves the developer a lot of time and effort. To do unit testing, your developer needs to write clear test code to test a specific function against an expected outcome. The tests will then run and any errors or failures to produce the expected outcome will be logged.
I created the OpenPojo project for solving this exact problem.
The project allows you to validate:
See Tutorial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With