lundi 31 août 2015

Maven Integration Tests With Spring Dependency

I have a project structure where I have the two following (Mavenized) projects:

Database - This project is a Spring project which manages interaction with the webapp's database. It contains code for interacting with the database, as well as many service classes. The Application Context here contains the database connection information, as well as beans for each service class.

WebApp - This project is a JSF project which just contains the UI stuff.

For unit testing the Database project, I have a testing Application Context which communicates with a very simple in-memory database-like structure, so the real database is not modified. The testing portion of this project also contains the structure for the in-memory database.

File Structure:

src/main/java/...
src/main/resources/spring/applicationContext.xml
src/test/java/...
src/test/resources/spring/applicationContext.xml

I want to create automated integration tests for the WebApp project which still uses the in-memory database stuff, as well as the testing Application Context, from the Database project. Unfortunately, Maven doesn't provide the WebApp project with the Database project's test code, so it isn't even accessible.

I tried working around that by using the maven-jar-plugin with the test-jar goal and added the test-jar as a dependency in Eclipse (since I read to do that for this problem), however Eclipse gives me the well known: "Dependency to project database with type test-jar is not fully supported. Classpath and/or deployment issues might arise. Try Maven->Disable Workspace Resolution" message, and doesn't update the dependency code when I make changes to the Database project, which means I have to perform a Maven build every time I make a change in the Database project for the test code in the WebApp project to work with the changes.

Database Project:

<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>

WebApp Project:

<dependency>
    <groupId>...</groupId>
    <artifactId>database</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>

Furthermore, Maven Clean no longer works on the Database project, since it says it cannot delete the test jar. Additionally, the command line doesn't run the tests with Database test jar, so the Maven Install on the WebApp project fails.

What should I do to make this work? I've heard about putting the test code into its own project and using that other project as a test dependency, but that won't work for me because the WebApp project needs to use the Database project's testing Application Context, so the problem is more than just access to the Database project's test code.

Aucun commentaire:

Enregistrer un commentaire