Java – is there a way to automate JUnit bean property testing?
Let's face it, writing bean property tests is probably the worst time usage But they need to finish
For example If the string property is tested for propname, the following is called:
testProperty(target,"propName",String.class); testProperty(target,String.class,"expected initial");
Will verify:
>Get and set methods exist. > If you test with the expected value to get the given value, call assertequals. > The (get, is) / set method runs as expected
I can start writing these implementations, but I wonder if there is anything available to facilitate this Other optional properties can be used to allow null validation or use JSR - 303 bean validation to validate fields
Solution
There are quite a few existing code bases / snippets to make this easier During a quick search, I found some potential:
> https://github.com/codebox/javabean-tester > http://code.google.com/p/junit-javabean-runner/ > http://javabeantester.sourceforge.net/
I've seen people take the first example I listed (good, simple, because it's just a separate class) and modify it to better meet their needs