0
PowerMockito 스파이를 사용하여 일부 코드를 테스트하려고하는데 테스터에 구성된 값을 반환하기 위해 메서드를 스텁 (getRootTagMap - 아래 참조)합니다 (메서드가 private이기 때문에 PowerMockito 사용).PowerMockito 스파이가 값을 반환한다고 말하면서 실제 메소드를 호출하는 이유는 무엇입니까?
그러나 값을 반환하는 대신 생성 된 값을 반환하지 않고 항상 실제 메서드를 호출합니다. 내가 뭐하는 거지
확실하지 잘못된
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.powermock.api.mockito.PowerMockito.spy;
@RunWith(PowerMockRunner.class)
@PrepareForTest({JsonAppMessageProcessor.class})
public class TestPropStoreAppController {
@Test public void testSaveJsonAppTagChangesToPropStore() throws Exception {
JsonAppMessageProcessor messageProcessorSpy = spy(new JsonAppMessageProcessor());
when(messageProcessorSpy, "getRootTagMap", any(JsonAppTag.class)).thenReturn(constructReturnValue());
// I tried it this way too...
// doReturn(constructReturnValue()).when(messageProcessorSpy, "getRootTagMap", any(JsonAppTag.class));
// the following call calls the real getRootTagMap(JsonAppTag) method instead of returning the stub
messageProcessorSpy.saveChanges(constructParameterForChanges());
}
}
혹시 문제가 무엇인지 알아 냈습니까? 지금 당장 같은 문제가있어 무엇을해야할지 모르겠다. https://stackoverflow.com/questions/38155092/powermockito-is-calling-the-method-when-i-use-doreturn-when – Ahmad