junit - How do you bypass static method calls? -


i have line interferring in unit test:

otherclass.staticmethodthatwillerrorifcalled().isavailable(); 

if wasn't static mock otherclass , this:

mockito.doreturn(null).when(mockedotherclass).staticmethodthatwillerrorifcalled(); mockito.doreturn(true).when(mockedotherclass).isguimode(); 

and fact error if called makes attempts @ using powermockito futile.

i'm not sure how can this. want skip on line (it's if check) , continue on if had returned true. best way this?

i require more info give more specific answer thinking...

first tell powermockito mocking static method in otherclass.

@runwith(powermockrunner.class) @preparefortest(otherclass.class) 

these class level annotations go on unit testing class.

then mock when method called.

powermockito.mockstatic(otherclass.class); mockito.when(otherclass.isavailable()).thenreturn(boolean.true); 

do in @before method on unit testing.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -