在maven测试依赖项上运行testNG

在maven测试依赖项上运行testNG,maven,testng,Maven,Testng,我有一个maven项目,它依赖于测试项目。我想在此项目上运行testNG: <groupId>com.myGroup</groupId> <artifactId>assembly</artifactId> <version>1.0.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.testn

我有一个maven项目,它依赖于测试项目。我想在此项目上运行testNG:

<groupId>com.myGroup</groupId>
<artifactId>assembly</artifactId>
<version>1.0.0-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.4</version>
    </dependency>
    <dependency>
        <groupId>com.myGroup</groupId>
        <artifactId>myArtifact</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <type>test-jar</type>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.4</version>
            <configuration>
            <test>MyTest</test>
                <suiteXmlFiles>
                    <suiteXmlFile>test-suites/all-test.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>
com.myGroup


看起来很合适。如果可以直接从依赖项运行代码,而不必解包,那就太好了。

乍一看,我在pom.xml中没有发现任何缺陷

请参考,我认为这就是您正在寻找的生成和执行测试二进制文件


这在Maven Surefire v2.15中现在是可能的。只需将以下类型的配置添加到surefire插件:

<build>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.15</version>
    <configuration>
      <dependenciesToScan>
        <dependency>com.group.id:my-artifact</dependency>
        <dependency>com.group.id:my-other-artifact</dependency>
      </dependenciesToScan>
      ...
    </configuration>
    ...
  </plugin>
  ...
</build>

org.apache.maven.plugins
maven surefire插件
2.15
com.group.id:我的工件
com.group.id:我的另一个工件
...
...
...
您还应该在“依赖项”部分声明实际的依赖项:

<dependencies>
  <dependency>
    <groupId>com.group.id</groupId>
    <artifactId>my-artifact</artifactId>
    <type>test-jar</type>
    <version>1.1</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.group.id</groupId>
    <artifactId>my-other-artifact</artifactId>
    <type>test-jar</type>
    <version>1.1</version>
    <scope>test</scope>
  </dependency>
</dependencies>

com.group.id
我的神器
试验罐
1.1
测验
com.group.id
我的另一件艺术品
试验罐
1.1
测验