简体   繁体   English

Maven-surefire插件和分叉模式

[英]Maven-surefire-plugin and forked mode

So I have some classes that rely on a jar file that has native methods in them. 因此,我有一些类依赖于其中具有本机方法的jar文件。 I am running into issues when mocking the objects in this jar file...so I have found a solution that works. 在模拟此jar文件中的对象时遇到了问题...因此我找到了一种可行的解决方案。

Using forkedmode pertest seems to fix this issue. 使用forkedmode pertest似乎可以解决此问题。 However, there are 5 files affected by needing to be run in forkedmode...there are 130 other tests that do not need forking, and the build time with cobertura and everything is VERY slow as it is forking for every test in that pom... 但是,有5个文件受需要以分叉模式运行的影响...还有130个不需要分叉的测试,并且使用cobertura的构建时间非常缓慢,因为该pom中的每个测试都分叉。 ..

So my question is...is there a way to specify which classes you want to run in forkedmode and run everything else normally? 所以我的问题是...是否有一种方法可以指定要在派生模式下运行哪些类并正常运行其他所有类?

is there a way to specify which classes you want to run in forkedmode and run everything else normally? 有没有一种方法可以指定要在派生模式下运行哪些类并正常运行其他所有类?

You can do this by specifying two <execution> elements with specific <configuration> : a default one for most tests (excluding those that need to be forked ) with the forkMode set to once and a special one for the special tests (including only the special one) where the forkMode set to always . 您可以通过指定两个具有特定<configuration> <execution>元素来做到这一点:对于大多数测试(不包括需要forked那些),默认一个将forkMode设置为once ,将一个特殊的用于特殊测试(仅包括特殊的一种),其中forkMode设置为always

Here is a pom snippet showing how to do this: 这是一个pom片段,显示了如何执行此操作:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <!-- Lock down plugin version for build reproducibility -->
  <version>2.6</version>
  <executions>
    <execution>
      <id>default-test</id><!-- here we configure the default execution -->
      <configuration>
        <forkMode>once</forkMode><!-- this is the default, can be omitted -->
        <excludes>
          <exclude>**/somepackage/*Test.java</exclude>
        </excludes>
      </configuration>
    </execution>
    <execution>
      <id>special-test</id><!-- and here we configure the special execution -->
      <phase>test</phase>
      <goals>
        <goal>test</goal>
      </goals>
      <configuration>
        <forkMode>always</forkMode>
        <includes>
          <include>**/somepackage/*Test.java</include>
        </includes>
      </configuration>
    </execution>
  </executions>
</plugin>

See also 也可以看看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM