brettw
brettw

Reputation: 11124

Separate maven test project that runs against two other projects

I have a project that has divided into two projects. The original project, let's call it Project-java6, and a new project, let's call it Project-java8. I need to release both artifacts, one for Java 6/7 users and one for Java 8 users.

The two projects are "identical", in that Project-java6 was simply copied to Project-java8 and the code in Project-java8 modernized (as expected, with Java 8 constructs). As it stands, both projects have identical unit tests. The "API" of Project-java6 and Project-java8 are identical, so I would like to separate out the unit tests so I'm not constantly updating the same code in two places (that already happens enough with the two projects).

So, I would like something like the following structure:

Project-java6 Project-java8 Tests

Where Tests is an "independent" maven project. My challenge (and thus this question) is: how to I get Tests to run against both Project-java6 and Project-java8? Meaning, when the parent pom is built, all three projects are built, and the tests are run against Project-java6 and Project-java8 respectively.

Upvotes: 2

Views: 54

Answers (1)

ivoruJavaBoy
ivoruJavaBoy

Reputation: 1357

I hope this could help you...

You can create an abstract test in the tests module, where you will write the main tests cases. This test will use the interface defined in the first module in the test.

Then, in each module Project-java6 and Project-java8, you create a test that extends the abstract test and call the test methods defined in the tests module.

Regarding Maven :

In the tests module, you will have to indicate to Maven that he has to create a jar of the tests package:

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

Then, in each implementing module, you will have to indicate that you have a dependency to this test-jar library:

<dependency>
    <groupId>foo</groupId>
    <artifactId>bar</artifactId>
    <version>${pom.version}</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>

I just read this answear in another post, and it seems to be good for you..

Let me know if all is clear...

Upvotes: 1

Related Questions