java 为什么不是 PowerMock
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30162200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why not PowerMock
提问by KKO
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.
我正在做一个项目,我们目前正在使用 JUnit 和 Mockito 进行测试。现在我试图找出将 PowerMock 添加到组合中的副作用。
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.
我看到它支持 Java 8。有什么问题吗?据我所知,获得 Java 7 支持是一条漫长的道路。
EDIT:I guess a questions that would sum it all would be:
编辑:我想可以总结的问题是:
What would be the reasons to not use PowerMock?
不使用 PowerMock 的原因是什么?
回答by wsl
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.
通常,如果您开始新项目并且由于您的代码架构而(想要/被迫)使用 PowerMock,则意味着该架构很糟糕,需要改进。Power Mock 使您可以访问模拟静态方法、构造函数等,这意味着您的代码没有遵循最佳编程原则。
Power Mockshould 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.
Power Mock应该用于您无法更改已提供给您的代码的遗留应用程序中。通常这样的代码没有单元/集成测试,即使是很小的改动也会导致应用程序中的错误。