Hi Krishantha,
I looked around to find the opinion of the java community on unit testing
DAO layer of codebase and found out different approaches. Below are few -

   - Not testing DAO layer at all [1]. This is not the most convincing
   approach.
   - Test the DAO layer by its own self. Create/Read/Update/Delete [2]
   - Use handwritten database queries and test them isolation [3]

To test a simple DAO class - the second method would be sufficient. But a
complex class that has foreign keys and depending DAO objects would be
tedious. One DAO would be to be used to insert a record for another DAO to
use. This destroys the idea of unit testing where we are testing an
isolated piece of code.

My suggestion would be to use the 3rd method for complicated scenarios like
above. And use second method for simple DAO testing. WDYT?

[1] - http://java.dzone.com/articles/stop-unit-testing-database
[2] -
http://tutorials.jenkov.com/java-unit-testing/database-testing-crud.html
[3] -
http://programmers.stackexchange.com/questions/219362/how-to-test-the-data-access-layer

Cheers~

-- 
Dulitha Wijewantha (Chan)
Software Engineer - Mobile Development
WSO2 Inc
Lean.Enterprise.Middleware
 * ~Email       duli...@wso2.com <duli...@wso2mobile.com>*
*  ~Mobile     +94712112165*
*  ~Website   dulitha.me <http://dulitha.me>*
*  ~Twitter     @dulitharw <https://twitter.com/dulitharw>*
  *~Github     @dulichan <https://github.com/dulichan>*
  *~SO     @chan <http://stackoverflow.com/users/813471/chan>*
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to