gpt4 book ai didi

java - Mockito doNothing UnfinishedStubbingException

转载 作者:行者123 更新时间:2023-12-01 18:47:14 29 4
gpt4 key购买 nike

当另一个方法中的 spyAnotherService.getUrl(ID) 时,我试图进行 spy /模拟并返回一个虚拟 Url,该方法是 myService.deleteSomething(name, spy AnotherService.getRepApiServiceUrl(ID)) 该方法有一个 void 返回类型。但它提示UnfinishedStubbingException。我检查了网络上的示例,但没有一个与我在这里尝试的内容相符

MyService myService = Mockito.mock(MyService.class);
AnotherService spyAnotherService = Mockito.spy(AnotherService.class);
Mockito.when(spyAnotherService.getUrl(ID)).thenReturn(URL);
Mockito.doNothing().when(myService).deleteSomething(name, spyAnotherService.getRepApiServiceUrl(ID));


最佳答案

你可以监视类(class)

MyService myService = Mockito.spy(MyService.class);

但是你don't need什么都不做(也是字面上的意思)

However, doNothing() is Mockito's default behavior for void methods.

关于java - Mockito doNothing UnfinishedStubbingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59807716/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com