在POM.xml中为多个依赖项目的Junit测试用例

时间:2013-12-30 19:17:44

标签: maven junit maven-2 junit4

我有一个项目Test-A,在这里我有应用程序的junit测试类。 现在,我有另一个名为Test-B的项目,在此我有应用程序的junit测试类。

Test-B,我已经包含了项目-A,即修改后的POM.xml,包含在:

的pom.xml:

<dependency>
    <groupId>com.abc.test-A</groupId>
    <artifactId>TestA</artifactId>
    <version>1.7</version>
    <scope>test</scope>
</dependency> 

问题: 当我为Test-B项目运行mvn test时,这也必须运行Test-A junit测试文件。我怎么能进行这种测试?

我是junit 4.9版本。

2 个答案:

答案 0 :(得分:1)

您必须使用Maven Source Plugin打包测试源。

以下是在安装部署项目时打包测试源的构建插件的示例:

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.2.1</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <phase>verify</phase>
            <goals>
              <goal>test-jar-no-fork</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

您必须将测试的依赖项添加为test-jar类型:

<dependency>
  <groupId>com.abc.test-A</groupId>
  <artifactId>TestA</artifactId>
  <version>1.7</version>
  <type>test-jar</type>
  <scope>test</scope>
</dependency>

现在您可以访问可以直接运行的工件TestA中的测试。

答案 1 :(得分:0)

为项目B运行测试不会对任何依赖项运行测试。例如,您的项目也将依赖于junit。您不希望这些测试运行。

相关问题