Junit friends DBUnit and Spring test framework :-)

Now-a-days TDD(Test driven development) is defacto standard in software developemnt. Don’t know what is TDD? It is all about writing unit test cases for your business logic or for your data access layer a.k.a DAO layer before you actually implement end-to-end implementation logic.

I have been writing unit test cases for more than 2 and half years, and generally I use Junit framework. Of course, JUnit is a standard across java space for unit testing.

Junit is simple to implement unit test framework for service/business logic. when it comes to database integration testing you may need to insert/delete lots of data in database for to initialize your test data. For this to acheive you need to write crude native database insert scripts and run in setup method or you may prefer writing text/xml file with the required data and read the files using some other api and then insert the data in database. All these things you have to manage yourself, and may requires you to write lots of bipolarate jdbc code, more complexity is involved when you use junit for integration tesitng.

Here comes spring test framework and DBUnit to simplify Junit and adds few usefull features which will ease the integration testing. These two frameworks are superset of Junit, means they extend junit and adds additional features.

DBUnit features

  • Manages the insert/delete data from database (you just need to provide data set xml file)
  • DBUnit helps you preparing data-set file, so no manual work :-)
  • Exports tables in order based on foreign key constraint

Spring test framework features

  • Provides dependency injection in your unit test class( you just need to load your spring config files)
  • Automatic transactions applied to all the test* methods, so need to write transaction code.
  • Automatic rollback after unit test execution completed.

Your comments are appreciated. Have a good day :-) :-)


Browse Realted Articles

    Bookmark and Share

    Leave a Reply