2
私はいくつかの方法を嘲笑して単体テストを書こうとしています。私はしかし、いくつかの問題に直面している、私はオブジェクトの一つが嘲笑されていないと信じている。Junit Mockitoが期待通りに嘲笑していない
class A {
Class_C c;
Class A(String x) {
c = new Class_C(x);
}
public boolean internalMethod(String internalInput) {
// Some Logic
// Calls Inet4Address.getByName(internalInput)
}
public boolean method_to_be_tested(String input) {
boolean result_1 = internalMethod(input);
boolean result_2 = c.someMethod(result_1);
}
}
私が書いたユニットテストは以下の通りです:
@Test
public void test_method_to_be_tested() {
A testObj = new A("test_input");
testObj.c = Mockito.mock(Class_C.class);
A spyTestObj = Mockito.spy(testObj);
Mockito.when(spyTestObj.internalMethod(Mockito.anyString())).thenReturn(true);
Mockito.when(spyTestObj.c.someMethod(Mockito.anyBoolean())).thenReturn(true);
Mockito.when(spyTestObj.test_method_to_be_tested("test_input")).thenCallRealMethod();
Assert.assertTrue(spyTestObj.test_method_to_be_tested("test_input"));
}
私は取得していますエラーが呼び出さなっているInet4Address.getByName()
を示しています。私はそれが呼び出されたメソッドの出力を嘲笑しているので、それはありません。