junit test问题# Java - 爪哇娇娃
I*o
1 楼
情况应该是比较common的,就是假设你要测试class A B C D E F
测试A需要有B和C的objects在db,
测试B需要有D和C的objects在db,
测试C需要有D, F和E的objects在db, etc...
那么这些test case怎么prepare test data呢?
现在的做法是在TestA的setup里面来
b1=insert(b); b2=insert(b); c1=insert(c); c2=insert(c);
a1=new A(b1, c1); a2=newA(b2, c2);
大概这样吧。可是这样一来有很多的重复代码,看着也不太clean,
尤其当这种data dependency复杂一些的话。
做了点research,看到一个叫Dependent Object framework的open source,
大概是定义a1.xml, a2.xml, b1.xml, b2.xml之类的xml,
这些xml定义这些test objects的data & dependency,有谁有经验么?
测试A需要有B和C的objects在db,
测试B需要有D和C的objects在db,
测试C需要有D, F和E的objects在db, etc...
那么这些test case怎么prepare test data呢?
现在的做法是在TestA的setup里面来
b1=insert(b); b2=insert(b); c1=insert(c); c2=insert(c);
a1=new A(b1, c1); a2=newA(b2, c2);
大概这样吧。可是这样一来有很多的重复代码,看着也不太clean,
尤其当这种data dependency复杂一些的话。
做了点research,看到一个叫Dependent Object framework的open source,
大概是定义a1.xml, a2.xml, b1.xml, b2.xml之类的xml,
这些xml定义这些test objects的data & dependency,有谁有经验么?