java - Unit testing after adding database with hibernate -


i've added database functionality using hibernate system in memory point. when data memory able use junit restored original data after each test. there way achieve same result new hibernate addition? "the same result" mean start database @ original state, test can alter database, , restore database original state.

up until ideas are:

  1. in memory database (which hibernate feature) won't allow me use actual data.
  2. add "testing flag" me doa won't commit changes if set.

i sure there better solution, haven't found better yet.

i think should clear definition of unit test. unit test must test small unit (a public method) in application.

assuming have dao layer uses hibernate interact database. hibernate uses sessionfactory requires datasource. data source of unit test should not same 1 production application.

the idea define test datasource , use in memory db (hsqldb or other). each of test case can execute queries on in memory db, using test datasource , clear after execution of unit test. each unit test should execute query test data setup done particular test.

for e.g.: if want test following: 1) create account 2) update account 3) delete account

then there 3 test scenarios , there can bee multiple unit tests possible each of scenario.

now before executing create account test, important db doesn't have account. , call createaccount method in dao test same. no need verify if result in db or not. check return of method , if same expected on successful account creation test case should pass.

for update account, setup method should insert 1 account through query , must call updateaccount in dao account id , on.

please stick definition of unit tests , not use testing more 1 functionality @ time.

hope helps.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -