我正在做一些测试,但我的嘲笑不起作用。
这是我的测试课。
@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class ResendMailingStrategyUnitTest {
@Test
public void sendTest() throws ResendException {
Resend resendClient = Mockito.mock(Resend.class);
Emails mockedEmails = Mockito.mock(Emails.class);
ResendMailingStrategy resendMailingStrategy = new ResendMailingStrategy();
ReflectionTestUtils.setField(resendMailingStrategy, "resendClient", resendClient);
Mockito.when(resendClient.emails()).thenReturn(mockedEmails);
Mockito.when(mockedEmails.send(Mockito.any(CreateEmailOptions.class))).thenReturn(null);
resendMailingStrategy.send(StubProvider.getEmailMessageModelStub());
Mockito.verify(resendClient).emails().send(Mockito.any(CreateEmailOptions.class));
}
}
但是我的 while(resendClient... 不起作用,因为方法没有返回模拟,然后我收到此错误;
无法调用“com.resend.services.emails.Emails.send(com.resend.services.emails.model.CreateEmailOptions)”,因为“com.resend.Resend.emails()”的返回值为null
我猜你必须使用 Inject Mocks 对于那些你已经嘲笑的依赖类。