In Maven, there is a clear directory structure for unit tests - they go in /src/test/java. Where do the integration tests go? These would be the tests that require a database to run so therefore run separately from the unit tests.
This page implies you can name the directory anything you want, but it doesn't seem like "the Maven way" to omit a configuration.
Also, any gotchas I should be aware of in this space?
Hmm, that doesn't make sense to me. Unless you do the integration test as a separate project, perhaps as a product POM (one that doesn't compile any Java source), rather than as a component POM (which has Java source and unit test source).
The reason for 2 separate source directories is to divide the source code that will be compiled to produce the deployable production from the source code that is compiled and used to run local testing. That's all.
The distinction between unit testing and integration testing on my systems is pretty blurry since I use dbUnit and it builds on jUnit. For external testing such as Cactus, I'd have a separate project.
One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
Warren Dew
blacksmith
Ranch Hand
Joined: Mar 04, 2004
Posts: 1328
posted
0
On some projects, the distinction between unit tests and integration tests is clear, if not in the place most people think of it. In particular, on my current project, unit tests are the tests that can be run without JBoss running; integration tests are the ones that require the JBoss container.
This appears to be the distinction that the maven lifecycle envisions, with a setup phase that would allow deployment into the container and starting it, which happens after the package phase but before the integration testing phase.
That said, there doesn't seem to be any established convention for where the tests should go. You can use some plugins and just name the tests differently, keeping them all in the test directory; other plugins envision an integration test directory in parallel to the test directory.
To me, the latter seems to be more consistent with the philosophy of maven, as the idea behind having a separate test directory in the first place is to distinguish tests on something other than just the name. I haven't actually gotten to the point where I'm converting integration tests to maven yet, though.
Has anyone actually gotten to that point, what was your situation, and how did you handle it?
src/main contains all the stuff needed to construct the raw deployable.
src/test contains all the stuff that gets added to the stuff from src/main in order for Maven to run tests, but which shouldn't be part of the deployed component. The primary tests in question are unit tests, but other tests can be run under Maven's control as well. Excepting cases where a specialized test mojor has its own conventions, the test resources would go under src/test
After a little more digging through the Surefire and Failsafe plugins, I found that by default the Surefire plugin runs tests with the the text "Test" in the class name, while the Failsafe plugin runs tests with the text "IT" in the class name. That's why both unit tests and integration tests can appear in the src/tests/java directory.
This method appears to work for the most part, though I wasn't able to get the resource files moved using his method. For future reference, I used a slight variation:
subject: maven - conventions for integration tests