从JDK 1.6迁移到JDK 1.7的PowerMockito测试越来越违反约束 [英] PowerMockito tests moved from JDK 1.6 to JDK 1.7 are getting constraint violations

查看:328
本文介绍了从JDK 1.6迁移到JDK 1.7的PowerMockito测试越来越违反约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些可以在JDK 1.6上正常运行的测试。现在,我们要迁移到JDK 1.7。这些测试在Eclipse中工作正常。当我们从Ant构建中运行这些测试时,我们看到这样的错误:

We have some tests that had been working fine with JDK 1.6. We're now moving to JDK 1.7. These tests work fine in Eclipse. When we run these tests from our Ant build, we're seeing errors like this:

junit.framework.TestListener: addError(<testmethodname>, loader constraint violation:
when resolving overridden method 
"com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Lorg/w3c/dom/Node;)Ljava/lang/Object;"
the class loader (instance of org/powermock/core/classloader/MockClassLoader) of the current class,
com/sun/xml/bind/v2/runtime/unmarshaller/UnmarshallerImpl, and its superclass loader (instance of <bootloader>),
have different Class objects for the type
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Lorg/w3c/dom/Node;)Ljava/lang/Object; used in the signature)

我们正在使用PowerMockito 1.5当我们第一次看到这个。我只是尝试升级到1.5.4和所有相关的依赖项,并且没有任何变化。

We were using PowerMockito 1.5 when we first saw this. I just tried upgrading to 1.5.4 and all the relevant dependencies, and that resulted in no change.

这显示了我们正在使用的类批注:

This shows the class annotations we're using:

@RunWith(PowerMockRunner.class)
@PowerMockIgnore({ "javax.xml.*", "org.xml.sax.*" })
@PrepareForTest(<classundertest>.class)
public class <classundertest>Test extends MockServiceBase {

这里可能是什么问题?

推荐答案

昨晚我终于找到了解决方法为了这。关键是要在 @PowerMockIgnore注释中添加其他程序包掩码。我尝试做的第一件事就是添加 com.sun.xml。。我以为这没什么区别,但我认为它只是解决了引用该软件包的测试。其余的引用是 com.sun.org。,但我没有意识到。当我最后还添加 com.sun.org。*时,它修复了其余测试。

Last night I finally found the workaround for this. The key was to add additional package masks to the "@PowerMockIgnore" annotation. Just about the first thing I tried was adding "com.sun.xml.". I had thought that didn’t make any difference, but I think it simply fixed the tests that referred to that package. The remaining references were to "com.sun.org.", and I didn’t realize that. When I finally also added "com.sun.org.*", it fixed the remaining tests.

这篇关于从JDK 1.6迁移到JDK 1.7的PowerMockito测试越来越违反约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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