Scala Dependency Injection and testing -
i looking @ alternatives(constructor params, di, etc) in following scenario. have integration test begins simple database entries, , tests etl pipeline transform entries. db connections needed within etl class tree, per actual program, in integration test class input original data. ive tried provide separate db access test class , etl lock errors. struggling best way go this
a quick unit test looks this:
class mytest extends testlibrary dbtestsupport { db.find("foo")... } trait dbtestsuport { //setup val db = externallibrary.database(port=800).open }
but want full integration test mock/test db , have contend kinds of inheritance.
class myfunctionaltest extends testlibrary { //somehow access db def addsometestdata = db.add(it: list[foo]) val items = list(foo(1), foo(2)) addsometestdata(items) //now lets test etl pipeline def transform = new transform().methodthatdoesthings...// transform.testmethodtoexpectthings// }
where db
access needed way further down:
class transform { def methodthatdoesthings = { stream.via(new coolstreammethod) //... } class coolstreammethod { //setup //**somehow need access dao dao.myquery map { results => process(results) } } class actordao { val actor = //create actor router forwards workers def myquery = actor ? coolquery } class worker extends actor { dao = //get access dao implementation def receive = { case q: coolquery => dao.find(q.thing) } class daoimpl { def find(item: bar) = db.find("item.id") // **database specific stuff externallibrary.database method needed in original unit test }
Comments
Post a Comment