mercredi 26 juillet 2017

org.powermock.reflect.exceptions.FieldNotFoundException: Field 'fTestClass' was not found in class

After being stuck a number of times when I encountered enums, final classes and private methods while trying to mock using Mockito , Now I am starting with Powermock along with mockito.

I have these libs in my pom:- junit: 4.11 mockito-core: 1.9.5 powermock-api-mockito: 1.5 powermock-core: 1.5 powermock-module-junit4: 1.5

I guess they are quite compatible , still I am facing below exception whien I am trying to run a simple test case like below- Exception:-

org.powermock.reflect.exceptions.FieldNotFoundException: Field 'fTestClass' was not found in class org.junit.internal.runners.MethodValidator.
    at org.powermock.reflect.internal.WhiteboxImpl.getInternalState(WhiteboxImpl.java:643)
    at org.powermock.reflect.Whitebox.getInternalState(Whitebox.java:308)

Test class:-

@RunWith(PowerMockRunner.class)
@PrepareForTest(ABCServiceImpl.class)
public class ABCServiceImplTest {

private ABCServiceImpl abcServiceImpl;

// A couple of @Mock objects defined in between (@Mock from Mockito)
      @Before
       public void setUp() throws Exception{
           abcServiceImpl =  PowerMockito.spy(new ABCServiceImpl());
           PowerMockito.doNothing().when(abcServiceImpl, "myPrivateMethod");   
       }

@Test
//My test method goes here ...

Can I be missing something here ?

Aucun commentaire:

Enregistrer un commentaire