Maven2 Integration Tests
It seems like integration tests with Maven are an afterthought.
Don't get me wrong, I think Maven is one of the best build tools so far. Sure, it has its warts, the documentation is weak (at best), and the learning curve is steep. But, once you get a project going, it's pretty much smooth sailing. Telling people how to build a project is reduced to saying, check it out of version control and run "mvn package". Want to run a local copy of the app, "mvn tomcat:run". Pretty sweet.
Back to the main topic. I've got integration tests running by using the cargo plugin. So, it unpackages and starts a tomcat server, deploys the app to it, runs the tests, and shuts down the server.
Nice. But, it feels like a hack. The process is cool, the definition in the pom, just doesn't feel right.
The module where the integration tests live must define its packaging as "pom". As such, it doesn't look like a java project to eclipse. If the packaging is changed to jar (to make it a java project for eclipse) then the integration tests don't run.
So, to work on this project:
- edit pom (change packaging to jar)
- mvn eclipse:eclipse
- edit pom (change packaging back to pom)
- import the project
It's not difficult but, it seems to violate convention over configuration. It also feels a little hacky.
Update: if you are using the m2eclipse plugin, then none of that needs to be done. It will set-up the project correctly.
Should there be a different kind of 'packaging' for integration test projects? Then the maven eclipse plugin could know and setup the project correctly.
The life-cycle phases are:
The phases make it appear as if integration tests receive the same concern as the other phases.
However, if we go a little deeper, we'll see this isn't the case.
For example, the standard directory layout doesn't define a place for the integration tests to live (or the resources for the integration tests).
The default life-cycle doesn't even mention the source files for the integration tests.
For unit tests, we get:
For integration tests we have:
Since integration tests don't get the same lifecycle as the test phase, getting resources from the classpath is much more difficult than it should be. With "test" there is a place defined for the source and resources to live.
Convention Over Configuration
Where the heck am I supposed to put the source code for my integration tests? (and the resources for those tests?)
I'd like to follow "convention over configuration" here but, there doesn't appear to be a convention.
I'm not sure there is a conclusion to this little rant. I can get integration tests to work. I actually do like working with Maven. It just seems, the brute force approach to integration tests don't fit with the whole Maven philosophy.
In my project, I have a separate child module for the integration tests. This lets the QA team have a "separate" place to put their code, while ensuring everybody on the team can run the tests. I just really wish that these tests could integrate with the project as smoothly as everything else.
Open for comments on DZone