Is there a way to automate junit bean property tests?
There are quite a few existing code libraries/snippets that make this easier. In doing a quick search I found a few that have potential:
- https://github.com/codebox/javabean-tester
- http://code.google.com/p/junit-javabean-runner/
- http://javabeantester.sourceforge.net/
I have seen someone take the first example I listed (nice and simple because it's just a single class) and modify it to better fit their needs.
Brett Ryan
I am an application developer with a responsibilities in Java/J2EE web, C#, Linux, jQuery, Objective-C, Progress Software (OpenEdge). I work mostly with rich clients, the NetBeans Platform and HTML environments.
Updated on June 15, 2022Comments
-
Brett Ryan almost 2 years
Let's face it, writing bean property tests is possibly the worst use of time. But they need to be done.
For example. If testing a
String
property forpropName
a call such as the following:testProperty(target, "propName", String.class); testProperty(target, "propName", String.class, "expected initial");
Would validate that:
get
andset
methods exist.- If using expected value a test to
get
callsassertEquals
for the given value. - (
get
,is
)/set
methods behave as expected.
I could go an start writing these implementations, but I want to know if there is something available to facilitate this. Other optional attributes could be used to validate that
null
is allowed or use JSR-303 bean validation to validate the field.