architecture - How to write Unit Test for manager running dao? -
i'm having simple test design problem, solve once , all.
i'm pretty used regular java design pattern there manager interface
(or facade) , set of dao interfaces
. concrete implementation of managerimpl
using concrete implementations of daoimpl
.
right i'm @ point of implementation, don't have database connected project yet, guess perfect time write proper unit tests without db :-)
i able mock methods of manager using mockito, since test under method (or called system under test) using dao internally, have mock dao well. unfortunately cannot without setting concrete dao implementation in manager, mymanager.setmydao(mockeddao)
, have pull out setmydao
method interface, of course breaks encapsulation , makes clean , perfect interfaces garbage.
so question is: how mock dao in tests while preserving clean manager-dao
architecture?
you should unit test concrete implementations, i.e. managerimpltest
, explicitly create managerimpl
, therefore have setmydao
methods available mocks. test not know manager interface
.
btw, not necessary create interfaces everything. in cases single implementation of managers , daos exist. if there no other strong reason (e.g. spring aop proxies or dependency separations), guess it's better don't create interfaces in sake of simplicity.
Comments
Post a Comment