Unit test utililities

Making unit tests over legacy code sometimes requires the need to inject some values into a property that is private, like in the example:

class MyClass {
private MyObject myProperty;
}

I found a nice tool that allows to address this issue in a nice manner.
(http://www.laughingpanda.org/mediawiki/index.php/Bean_Inject)

So what you’d like to do in such a situation would be something like :

MyClass obj = new MyClass();
MyObject myProp = new MyObject();

Inject.property(“myProperty”).of(obj).with(myProp);

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply