2

I need to use Mockito/Power Mockito to mock a private method. I am using testng, and most of the examples I see online are for mocking private method using PowerMock+Junit - Mocked private method with PowerMock, but underlying method still gets called

Can anyone please point me to examples where I can use Power Mockito+testng. I have been looking for a while, but no luck so far.

Assafs
  • 3,257
  • 4
  • 26
  • 39
rickygrimes
  • 2,637
  • 9
  • 46
  • 69

3 Answers3

1

You can use spy, refer below link https://www.baeldung.com/powermock-private-method

Also, using whitebox you can do this How to mock private methods using Whitebox(org.powermock.reflect)

0

Here are examples with PowerMock and PowerMockito , right off of SO:

Community
  • 1
  • 1
Keith
  • 3,079
  • 2
  • 17
  • 26
0

i found the way . please try this

 @Test
        public  void  commandEndHandlerTest() throws  Exception
        {
            Method retryClientDetail_privateMethod =yourclass.class.getDeclaredMethod("Your_function_name",null);
            retryClientDetail_privateMethod.setAccessible(true);
            retryClientDetail_privateMethod.invoke(yourclass.class, null);
        }
Arun Yadav
  • 203
  • 3
  • 9