我们有一些测试在 JDK 1.6 上运行良好。我们现在正在转向 JDK 1.7。这些测试在 Eclipse 中运行良好。当我们从 Ant 构建运行这些测试时,我们会看到如下错误:
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 和所有相关的依赖项,但没有发生任何变化。
这显示了我们正在使用的类注释:
@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.*”时,它修复了剩余的测试。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)