1
我遇到PIT突變問題,如果它刪除class.callVoidMethod()它倖存下來。我假設我只需要驗證通話是否已完成,但我無法讓測試案例變綠。我嘗試過Spying和Mocking,但我發現這個模擬與零交互。在調試時,我看到的仍然是調用真正的方法。任何想法如何讓它使用模擬?使用Mockito驗證從另一個類的方法被稱爲
方法測試:
public void someMethod(String word)
{
word = "class"
SomeClass class = new SomeClass();
class.callVoidMethod(word, "char");
}
測試用例:
@InjectMocks
ClassUnderTest underTest;
@Mock
SomeClass class;
@Test
public void testSomeMethod()
{
underTest = new ClassUnderTest();
//Not Sure if I need this
Mockito.doCallRealMethod()
.when(class).callSomeVoidMethod(anyString());
underTest.someMethod("test");
Mockito.verify(class).callSomeVoidMethod(anyString());
}
'class'是保留關鍵字。這是一個錯字嗎? – callmepills