@PowerMockIgnore在项目级别 [英] @PowerMockIgnore at project level

查看:716
本文介绍了@PowerMockIgnore在项目级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Maven中运行时,在powermock测试用例中出现以下错误:

I have following error in my powermock test cases while running in Maven :

java.lang.LinkageError: loader constraint violation: loader (instance of org/powermock/core/classloader/MockClassLoader) previously initiated loading for a different type with name "javax/management/MBeanServer"

解决方案是添加注释

   @PowerMockIgnore("javax.management.*")

问题是我有很多测试文件,必须在其中添加此批注.

The problem is I have many test files where I have to add this annotation.

是否可以在项目级别或maven中添加它?

Is there a way to add this at project level or in maven?

谢谢

推荐答案

我认为这不可能.

请记住,最后,是 JUnit 执行这些测试用例.逐个.而且JUnit对周围的Maven项目"一无所知.

Keep in mind, in the end, it is JUnit that is executing those testcases. One by one. And JUnit knows nothing about a maven "project" around.

JUnit仅知道将要处理的测试类中的元素.

JUnit only knows about the elements within the test class it is about to process.

因此:这些语句需要进入您所有的测试用例;理想情况下,仅在真正需要它的人中.

Thus: those statements need to to go into all your testcases; ideally only in those that really require it.

最后一句话:请不要误会我的意思,但是我认为您的真正问题是,您似乎在项目中随意使用了PowerMock.这可能表明您的许多开发人员都不知道如何编写 testable 代码...,然后他们转向PowerMock对其进行修复".您有一定的机会迟早会为此感到后悔.

Final word: please don't get me wrong, but in my opinion your real problem is that you seem to use PowerMock indiscriminately in your project. That could indicate many of your developers dont know how to write testable code ... and then they "fix" that by turning to PowerMock. There is a certain chance that you will regret that sooner or later.

用于学习如何编写可测试的代码---从此处开始!

for learning how to write testable code --- start here!

这篇关于@PowerMockIgnore在项目级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆