第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JPA 單元測試用例刪除操作需要但未調(diào)用

JPA 單元測試用例刪除操作需要但未調(diào)用

天涯盡頭無女友 2022-09-28 16:15:00
在嘗試使用JPA創(chuàng)建用于刪除的junit測試用例時,我遇到了一些問題。在我的服務(wù)類中,我使用的是 JPA 提供的缺省函數(shù):public void delete(Long id) {        log.debug("Request to delete Enroll : {}", id);        enrollRepository.deleteById(id);}然后我的單元測試,我試圖模擬一個對象,然后執(zhí)行刪除:@Testpublic void testDeleteEnrollExpectSuccess() {    Enroll enroll = prepareEnrollWithBedAllocation();    enrollService.delete(enroll.getId());    verify(enrollRepository, times(1)).delete(enroll);}我打算像這樣嘲笑注冊對象:private Enroll prepareEnrollWithBedAllocation() {    LocalDateTime localDateTime = LocalDateTime.now();    ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, ZoneId.of("UTC"));    Enroll enroll = new Enroll();    enroll.setId(new Long(1));    enroll.seteDate(zonedDateTime);    enroll.setEbStartdt(zonedDateTime);    enroll.setEbEnddt(zonedDateTime);    enroll.setBed(prepareBed());    enroll.setPatient(preparePatient());    enroll.setDoc(prepareDoc());    enroll.seteCondition("Normal");    return enroll;}但是,我收到這些錯誤消息,并且我的測試用例失?。篧anted but not invoked:enrollRepository.delete(    Enroll{id=1, eCondition='Normal', eRemarks='null', ebStartdt='2019-04-09T16:40:32.703Z[UTC]', ebEnddt='2019-04-09T16:40:32.703Z[UTC]', eDate='2019-04-09T16:40:32.703Z[UTC]'});-> at com.team.generated.service.EnrollServiceTest.testDeleteEnrollExpectSuccess(EnrollServiceTest.java:61)However, there was exactly 1 interaction with this mock:enrollRepository.deleteById(1L);-> at com.team.generated.service.EnrollService.delete(EnrollService.java:74)有什么想法嗎?謝謝!
查看完整描述

1 回答

?
qq_遁去的一_1

TA貢獻(xiàn)1725條經(jīng)驗 獲得超8個贊

該錯誤本身就說明了:您正在驗證該方法:delete(Long id)

verify(enrollRepository, times(1)).delete(enroll);

但是,您的服務(wù)對象調(diào)用方法:deleteById()

enrollRepository.deleteById(id);

我想你想這樣做:

@Testpublic void testDeleteEnrollExpectSuccess() {  
  Enroll enroll = prepareEnrollWithBedAllocation();
    enrollService.delete(enroll.getId());
    verify(enrollRepository, times(1)).deleteById(enroll.getId());
}


查看完整回答
反對 回復(fù) 2022-09-28
  • 1 回答
  • 0 關(guān)注
  • 95 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號