Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why not PowerMock [closed]

I am working on a project where we are currently doing testing with JUnit and Mockito. Now I am trying to find out what would be the side effects of adding PowerMock to the mix.

What are its disadvantages, any dependencies I should know about, any stability issues?

I saw it supports Java 8. Are there any issues there? From what I've read, getting Java 7 support was quite a long road.

EDIT: I guess a questions that would sum it all would be:

What would be the reasons to not use PowerMock?

like image 301
KKO Avatar asked May 11 '15 07:05

KKO


People also ask

Why should we not use PowerMock?

Power Mock gives you access to mock static methods, constructors etc. and this means that your code is not following best programming principles. Power Mock should be used in legacy applications where you cannot change the code which has been given to you.

Should we avoid PowerMock?

In general, I would say yes, we should avoid usage of Powermock. One doubtful case I see for it - you have no time for appropriate design of you code to make it testable enough without power-mockito (, but do you really need that quality of testing, if you don't have time for code-design?)

Why do we use PowerMock?

The main aim of PowerMock is to extend the existing APIs with some methods and annotations to provide extra features that make unit testing quite easy. The PowerMock framework provides a class called PowerMockito used to create mock objects and initiates verification and expectation.

What is the difference between PowerMock and Mockito?

While Mockito can help with test case writing, there are certain things it cannot do viz:. mocking or testing private, final or static methods. That is where, PowerMockito comes to the rescue. PowerMockito is capable of testing private, final or static methods as it makes use of Java Reflection API.


1 Answers

Generally if you start new project and you (want to/ are forced) to use PowerMock because of the architecture of your code it means that this architecture is bad and needs improvement. Power Mock gives you access to mock static methods, constructors etc. and this means that your code is not following best programming principles.

Power Mock should be used in legacy applications where you cannot change the code which has been given to you. Often such code does not have unit/integration tests and even small change can result in bugs in application.

like image 158
wsl Avatar answered Oct 07 '22 15:10

wsl