【问题标题】:PowerMockito tests moved from JDK 1.6 to JDK 1.7 are getting constraint violations从 JDK 1.6 迁移到 JDK 1.7 的 PowerMockito 测试出现约束违规
【发布时间】:2014-02-02 20:51:07
【问题描述】:

我们有一些测试在 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 {

这里可能有什么问题?

【问题讨论】:

    标签: java eclipse java-7 mockito powermock


    【解决方案1】:

    昨晚我终于找到了解决方法。关键是在“@PowerMockIgnore”注释中添加额外的包掩码。我尝试的第一件事就是添加“com.sun.xml.”。我曾认为这没有任何区别,但我认为它只是修复了引用该包的测试。其余的引用是“com.sun.org.”,我没有意识到这一点。当我最后还添加了“com.sun.org.*”时,它修复了剩余的测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-15
      • 1970-01-01
      • 1970-01-01
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多