加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

如何在我的java项目中引用maven依赖的单元测试类?

发布时间:2020-12-14 05:47:43 所属栏目:Java 来源:网络整理
导读:我需要在项目A的测试包src / test / java中引用项目B中的一些JUnit测试(src / test / java),而B是A的maven依赖项. 这甚至可能吗? dependency groupIdXYZ/groupId artifactIdB/artifactId version${project.version}/version typejar/type scopetest/scope/d
我需要在项目A的测试包src / test / java中引用项目B中的一些JUnit测试(src / test / java),而B是A的maven依赖项.

这甚至可能吗?

<dependency>
    <groupId>XYZ</groupId>
    <artifactId>B</artifactId>
    <version>${project.version}</version>
    <type>jar</type>
    <scope>test</scope>
</dependency>

这两个项目都在我的控制之下.

谢谢你的建议

解决方法

你在项目B中的pom需要包含这个插件:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.5</version>
    <executions>
        <execution>
            <goals>
                <goal>test-jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

然后,您可以从项目A访问它,如下所示:

<dependency>
    <groupId>XYZ</groupId>
    <artifactId>B</artifactId>
    <version>${project.version}</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>

将“type”更改为test-jar允许您从该依赖项访问测试类.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读