简体   繁体   中英

Java How can I use a maven sub project for my integration tests?

I would like to make a separate project for my integration tests.

My current structure is like this (Maven project):

my-project-parent
   my-project-lib (jar)
   my-project-web (war)

Inside the lib sub project is the logic of my project. Inside the web sub project is everything that is related to my Servlets. There is still a lot of logic in there that makes it possible to handle all the different requests.

The sub projects have unit tests. Now the unit tests and integration tests are scrambled in the project and it's hard to see if it is a unit test or an integration test. By putting the integration tests in a separate project it also makes it possible to manage whether to run the integration tests.

Because of this I would like to create another sub project with all the integration test (my-project-it).

So far I have a separate project called “my-project-it”. I can do some test on the lib sub project. The problem I ran in to was that I needed a lot of classes from my-project-web. I'm unable/not willing to put the war as a dependency.

Can anyone help me with this?

There is an (old but) good wiki article about integration testing with maven.

I personally prefere a separate module that contains all the integration tests in src/it/java . This module can be activated with a maven build profile . The tests are run and the results verified with the failsafe plugin .

hth,
- martin

I would move all classes that are needed for my-project-it from my-project-web to my-project-jar and made it my-project-it's dependency.

Another option is instead of creating a separate my-project-it project create a separate package for integration tests under src/test/java and execute them with maven-failsafe-plugin http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM