我是模拟测试新手。
我想测试我的服务方法CorrectionService.correctPerson(Long personId)
。
实现尚未编写,但这就是它将执行的操作:
CorrectionService
将调用一个方法AddressDAO
这将删除一些Adress
that a Person
有。一Person
有很多Address
es
我不确定我的基本结构是什么CorrectionServiceTest.testCorrectPerson
.
另外请不要/不要确认在这个测试中我不需要测试地址是否确实被删除(应该在AddressDaoTest
),只是调用了 DAO 方法。
谢谢
更干净的版本:
@RunWith(MockitoJUnitRunner.class)
public class CorrectionServiceTest {
private static final Long VALID_ID = 123L;
@Mock
AddressDao addressDao;
@InjectMocks
private CorrectionService correctionService;
@Test
public void shouldCallDeleteAddress() {
//when
correctionService.correct(VALID_ID);
//then
verify(addressDao).deleteAddress(VALID_ID);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)