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