如何使用Maven项目在JAR中添加测试类 [英] How to add test classes in JAR with Maven project

查看:79
本文介绍了如何使用Maven项目在JAR中添加测试类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将测试类包含在Maven项目的生成的JAR中.

I am trying to include my test classes in a generated JAR in a Maven Project.

我已经创建了Maven项目并使用JUnit创建了测试类.

I have created the Maven project and created the test classes with JUnit.

当我尝试构建JAR时,这些测试类未包含在生成的JAR中.

When I am trying to build the JAR, these test classes are not included in the generated JAR.

推荐答案

您可以生成一个jar,其中将包含您的测试类和资源. 请参考Maven官方网站- https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html

You can produce a jar which will include your test classes and resources. Please refer maven official site - https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.0.2</version>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

这篇关于如何使用Maven项目在JAR中添加测试类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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