SimLine SimLine - 1 month ago 5
Java Question

How to create a jar with tests and run it from another version of project?

I have a project with version 1.0 with 3 package (maven projects).

project1 (version 1.0)

--------backward-tests (src/test/java + pom.xml)

--------pack1 (src/main/java + pom.xml)

--------pack2 (src/main/java+ pom.xml)


I want to save backward-tests jar with tests from here for using in version 1.x, where x > 1.

The project with version 1.x will show like the following:


project1 (version 1.1)

--------run-tests (pom.xml)

--------pack1 (src/main/java + pom.xml)

--------pack2 (src/main/java+ pom.xml)


Thr question: How should be the pom.xml files in backward-tests and run-tests packages for let me run the tests?
I have to mention that backward-tests has dependecies of pack1 and pack2.

Thank you.





Edit:

I have tried something like that in run-tests pom.xml:


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<dependenciesToScan>
<dependency>groupId:artifactId</dependency>
</dependenciesToScan>
</configuration>
</plugin>


but it doesn't work.

Answer

In backward-tests add this plugin to pom.xml that maven package the test class in backward-tests-test.jar

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

In run-tests add this dependency

   <dependency>
        <groupId>groupId</groupId>
        <artifactId>backward-tests</artifactId>
        <version>1.x</version>
        <type>test-jar</type>
        <scope>test</scope>
        <exclusions>
                <exclusion>
                    <groupId>groupId</groupId>
                    <artifactId>pack1</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>groupId</groupId>
                    <artifactId>pack2</artifactId>
                </exclusion>
       </exclusions>
    </dependency>
Comments