Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

maven - conventions for integration tests

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't use maven but did a little google'ing and found this, if you're still on Maven2.

http://cchweblog.wordpress.com/2009/06/25/integration-test-with-maven/
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the Failsafe plugin documentation the default integration test source location is the same as for unit tests:
http://maven.apache.org/plugins/maven-failsafe-plugin/integration-test-mojo.html



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).
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

See the includes property:
http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#includes
http://maven.apache.org/plugins/maven-failsafe-plugin/integration-test-mojo.html#includes
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter Johnson wrote:while the Failsafe plugin runs tests with the text "IT" in the class name.

Ugh. And thanks.
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Ugh. And thanks.

I agree with the reaction.

I've found a site that provides a method to use an integration test directory separate from the unit test directory:

http://johndobie.blogspot.com/2011/06/seperating-maven-unit-integration-tests.html

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:


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic