在maven打包阶段之后,如何执行Junit测试用例? [英] How do I execute Junit test case after package phase in maven?

查看:531
本文介绍了在maven打包阶段之后,如何执行Junit测试用例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在构建jar上运行Junit,但是在测试阶段的软件包阶段之前,在类文件上执行了maven surefire插件,在构建一个jar项目之后,是否可以运行所有junit. 在构建jar上运行的原因是为了验证jar的混淆性.

I want to run my Junit on my build jar's, but maven surefire plugin executed on class file before package phase that is at test phase, is there any way to run all junit after building a jar of project. Reason to run on build jar is to verify obfuscation of jar.

推荐答案

解决方案是使用 maven-failsafe-plugin ,它将进入集成测试阶段.您需要将此文件添加到pom文件中:

Solution is to use the maven-failsafe-plugin which will in the integration test phase. You need to this to your pom file:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.19.1</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

您应该遵循公约,并遵循集成测试的命名约定:

You should following the conventions and follow the naming conventions of integration tests:

<includes>
 <include>**/IT*.java</include>
 <include>**/*IT.java</include>
 <include>**/*ITCase.java</include>
</includes>

之后,您可以通过以下方式运行这些集成测试:

Afterwards you can run those integration tests via:

mvn clean verify

如果您想运行仅单元测试:

mvn clean test

这篇关于在maven打包阶段之后,如何执行Junit测试用例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆