How to apply unit test on DAOs in java -


i don't know how apply unit tests on data access layer. wonder if data access layer should tested. in company, have stable database store unit test data , test data access layer running data access objects , check data stable database.

in order pass unit tests, data in stable database can not modified anymore. think there better solution this. if not mistaken, the mock object cannot perform tests on sql statements , resultset mappings.

what best way unit test dao? there better way tdd?

first, definitions, "unit" tests not depend on external systems database. want create called "functional" or "integration" tests. in practice these types of tests implemented in same way unit tests, using junit, should separate them unit tests, should run fast , not break when database down or data has changed.

second, try keep of business logic out of daos , instead put service pojo layer can test biz logic without involving database.

next, ideal way set testing daos start empty database, , load test data (often using daos themselves), , run dao tests against known, , writable, test dataset. if you're fortunate enough have read-only database, stable database approach outline work, systems read/write database.

finally, valuable test daos. database queries of fragile parts of system, , don't want wait until deployed production find out breaking.


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -