[英]How to import JUnit tests from one Maven project into another?
I have two Eclipse projects A and B that I use to run Selenium tests with JUnit.我有两个 Eclipse 项目 A 和 B,用于使用 JUnit 运行 Selenium 测试。
In both projects, my test code is located under src/test/java
, because I need to be able to test both separately.在这两个项目中,我的测试代码都位于src/test/java
,因为我需要能够分别测试两者。
The problem is that I can't reuse tests from A
in B
because I can't import the test packages from A
.问题是我无法在B
重用A
中的测试,因为我无法从A
导入测试包。 I tried to fix this by placing A
's packages in its src/main/java
folder instead, but that means I can no longer run A
's test suites separately because it no longer has any tests to speak of.我试图通过将A
的包放在其src/main/java
文件夹中来解决这个问题,但这意味着我不能再单独运行A
的测试套件,因为它不再有任何测试可言。
What I want to do is to simply have tests in my Project A, that I can execute, but to be able to reuse those test classes in Project B without duplicating code.我想要做的是在我的项目 A 中简单地进行测试,我可以执行这些测试,但能够在项目 B 中重用这些测试类而无需复制代码。 How can I do this?我怎样才能做到这一点?
You can package your test code in its own artifact您可以将测试代码打包到自己的工件中
<!-- Packaging of test classes in JAR file -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
You can then import the dependency where you need it然后,您可以在需要的地方导入依赖项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.