JUnit测试中的java重写方法
我需要编写基于耦合的测试来观察几个路径。
我正试图像平常一样使用Assert.*
进行测试(我不知道更好的方法),但出于这个目的,我需要改变测试方法
考虑下面的例子
Class A {
public Collection<Object[]> mth1(String a);
do whatever
do whatever
B.mth2(a)
do whatever
return null
Class B
public void mth2 (String a)
a.parse();
do whatever
return null
对于我的测试,我对实际值不感兴趣,我只需要知道我的测试是否达到了某一点
因此,我想以这种方式重写mth2
,在第11行调用return
和mth1
调用第6行返回值1
有没有办法做到这一点或更好的方法来测试耦合
# 1 楼答案
使用模拟库(谷歌搜索模拟库)。为类B创建一个模拟对象。在测试中使用它