jeudi 23 avril 2015

Why when mocking a private method using Powermock is calling the real method?

I mock a method using a line like this in the @Before test method:

PowerMockito.when(mockedObject, method(MockedClass.class, "methodIWantToMock")).
            withArguments(Matchers.anyString()).thenReturn("AnyExpectecResult");

I tried this as well:

Whitebox.invokeMethod(mockedObject, "methodIWantToMock", "AnyExpectecResult");

I mock it because I don't want to execute it, but when those lines are executed, the real method is called, and I want to avoid that. I don't know why it is happening and how to avoid it. I couldn't find any question like this one in the site and internet. Any ideas? Thanks.

Aucun commentaire:

Enregistrer un commentaire