【问题标题】:Junit Test Error: No field 'segmentmask' found in class 'java.util.concurrent.ConcurrentHashMap'Junit 测试错误:在类“java.util.concurrent.ConcurrentHashMap”中找不到字段“segmentmask”
【发布时间】:2015-07-24 10:24:30
【问题描述】:

尝试在 Maven 项目中使用 PowerMockRule 运行 Arquillian 测试,以便能够模拟静态类。

但是,当我构建 maven 项目时,我在测试中收到以下错误:

测试错误: myTest(com.package.myTest):无法调用 java.util.concurrent.ConcurrentHashMap.readObject():在类“java.util.concurrent.ConcurrentHashMap”中找不到字段“segmentmask”

我不知道这个问题的原因以及如何解决它。任何建议将不胜感激,谢谢。

编辑:显然问题是由使用 PowerMockRule 所需的 XStream 类加载器引起的。但我还没有找到解决办法。

【问题讨论】:

    标签: maven junit powermock xstream jboss-arquillian


    【解决方案1】:

    这确实是由 x-stream 问题引起的(在 1.4.8 中已修复): http://x-stream.github.io/jira/761/

    因此,如果您使用 maven 进行依赖管理,您可能希望在依赖管理中执行以下操作:

      <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-classloading-xstream</artifactId>
        <version>${powermock.version}</version>
        <scope>test</scope>
        <exclusions>
          <exclusion>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
          </exclusion>
        </exclusions>
      </dependency>
      <!-- Should be removed as soon as xstream is updated in powermock -->
      <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
        <version>1.4.8</version>
        <scope>test</scope>
      </dependency>
    

    然后你在哪里使用 powermock:

    <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-classloading-xstream</artifactId>
      <scope>test</scope>
    </dependency>
    <!-- Should be removed as soon as powermock has the latest version of xstream -->
    <dependency>
      <groupId>com.thoughtworks.xstream</groupId>
      <artifactId>xstream</artifactId>
      <scope>test</scope>
    </dependency>
    

    至少,直到 powermock 开始使用新的 x-stream 版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-19
      • 2017-08-30
      • 2017-06-08
      • 2014-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多