Run JUnit Tests contained in dependency jar using Maven Surefire

后端 未结 3 1481
广开言路
广开言路 2020-11-29 06:28

I have a jar in my maven repository that contains junit tests, which should be run in different projects, because it is able to inspect the project and test for certain feat

相关标签:
3条回答
  • 2020-11-29 07:09

    (This is just restating what is in a comment above from khmarbaise, but since it wasn't clarified, I think it's worth restating):

    Use the test-classes directory instead of the classes folder as outputDirectory:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>unpack</id>
                <phase>process-test-classes</phase>
                <goals>
                    <goal>unpack</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>de.mwx.test</groupId>
                            <artifactId>selenium-test-base</artifactId>
                            <version>0.1</version>
                            <overWrite>true</overWrite>
                              <outputDirectory>
                                  ${project.build.directory}/test-classes
                              </outputDirectory>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>
    
    0 讨论(0)
  • 2020-11-29 07:24

    There is a way of running a test in maven from another jar. from maven-surefire-plugin version 2.15 you can tell maven to scan your test jars for tests and run them. You don't need to extract the tests jar. Just add a dependency to your test jar and:

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <dependenciesToScan>
                    <dependency>test.jar.group:test.jar.artifact.id</dependency>
                </dependenciesToScan>
            </configuration>
        </plugin>
    

    Took this stuff from https://gist.github.com/aslakknutsen/4520226 And https://issues.apache.org/jira/browse/SUREFIRE-569

    As expected, this works for JUnit and Testng. Will probably work for anything that surefire can run.

    0 讨论(0)
  • 2020-11-29 07:25

    As described in the issue you need to have a Suite which is contains in your project which is NOT located in the test jar.

    0 讨论(0)
提交回复
热议问题