Why BeanUnit

I have a lot of basic beans with just getters and setters. Even though you can generate them within your IDE, later manual editing will eventually take place and are therefor important to test. Testing these beans take a lot of time and are often skipped because it is boring to do and maintain. That's why I created BeanUnit.

Extension on JUnit

BeanUnit is an extension to JUnit and assumes you use Junit 4.4. Under the covers it uses some xulux components (mainly the Bean Xulux DataProvider) to do the "magic".

Default Usage

AssertBean(Classname);

If the bean tests the following behaviour of your beans :

  • A default (empty) constructor.
  • Getter and Setter name match (so Name() and setName).
  • The first get call will return null.
  • Call the Setter with an object created by BeanUnit.
  • Call the Getter, expecting the same object back.
  • Call the Setter with a null value.
  • Call the Getter, expecting a null value back.
  • In case of enums as parameters, it retrieves the first value of the enum to set as value.

    If your bean / object has these conventions, your code coverage will be 100%. If they are not according to these conventions, the test will fail forcing you to write a test for the method by hand, or use the BeanUnitConfiguration.

Custom Usage

The BeanUnitConfiguration is used for those beans/objects that don't follow the default BeanUnit use case. My vision is that everything that is non default behaviour should be specifically typed, so when the object behaviour changes, the test will fail.

Create a BeanUnitConfiguration

Non Default Constructor

If you have a non default constructor on your bean you can use BeanConfiguration.nonDefaultConstructor(ObjectToUseInConstructor)