Maven Junit测试错误:没有字段';分段掩码';在类'中找到;ConcurrentHashMap';

Maven Junit测试错误:没有字段';分段掩码';在类'中找到;ConcurrentHashMap';,maven,junit,powermock,xstream,jboss-arquillian,Maven,Junit,Powermock,Xstream,Jboss Arquillian,尝试在Maven项目中使用PowerMockRule运行Arquillian测试,以便能够模拟静态类 但是,当我构建maven项目时,我在测试中遇到以下错误: 错误测试: myTest(com.package.myTest):无法调用java.util.concurrent.ConcurrentHashMap.readObject():在类“java.util.concurrent.ConcurrentHashMap”中未找到字段“segmentmask” 我不知道这是什么原因,也不知道如何着手

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

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

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

我不知道这是什么原因,也不知道如何着手解决。如果您有任何建议,我们将不胜感激,谢谢


编辑:显然问题是由使用PowerMockRule时需要的XStream类装入器引起的。但我还没有找到修复方法。

这确实是由x-stream问题引起的(在1.4.8中已修复):

因此,如果您使用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>

org.powermock
powermock类加载xstream
${powermock.version}
测验
com.thoughtworks.xstream
xstream
com.thoughtworks.xstream
xstream
1.4.8
测验
然后在使用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>

org.powermock
powermock类加载xstream
测验
com.thoughtworks.xstream
xstream
测验

至少,在powermock开始使用新的x-stream版本之前。

这确实是由x-stream问题引起的(在1.4.8中已修复):

因此,如果您使用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>

org.powermock
powermock类加载xstream
${powermock.version}
测验
com.thoughtworks.xstream
xstream
com.thoughtworks.xstream
xstream
1.4.8
测验
然后在使用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>

org.powermock
powermock类加载xstream
测验
com.thoughtworks.xstream
xstream
测验
至少,直到powermock开始使用新的x-stream版本