I want to check that the method public static void was called .
@RunWith(PowerMockRunner.class) @PrepareForTest({ConsoleLog.class}) public class AdContentDataUnitTest { @Before public void setUp() throws Exception { PowerMockito.mockStatic(ConsoleLog.class); } @Test public void adContentData_sendTrackingEvent_noUrl() throws Exception { mAdContentData = spy(mAdContentData);
sendTrackingEvent will be called, and ConsoleLog.v(String, String) will be called. In debugging, you can see that the static method is being called, but the following log appears and the test fails:
Wanted but not invoked com.example.logger.ConsoleLog.v( "AdContentData", "sendTrackingEvent: event event1 does not exist." );
I tried adding verifyStatic after the same log, and if I delete the first check, nothing will be verified. If I make fun of the entire ConsoleLog class, an Unfinished stubbing detected here: [...] PowerMockitoCore.doAnswer error occurs Unfinished stubbing detected here: [...] PowerMockitoCore.doAnswer .
Does anyone know how to do this correctly?
source share