File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes maven - conventions for integration tests Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "maven - conventions for integration tests" Watch "maven - conventions for integration tests" New topic
Author

maven - conventions for integration tests

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31062
    
232

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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/


GenRocket - Experts at Building Test Data
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

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


JBoss In Action
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Warren Dew
blacksmith
Ranch Hand

Joined: Mar 04, 2004
Posts: 1332
    
    2
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

Joined: Jun 25, 2001
Posts: 16305
    
  21

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

Joined: May 14, 2008
Posts: 5845
    
    7

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

Joined: May 26, 2003
Posts: 31062
    
232

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

Joined: Mar 04, 2004
Posts: 1332
    
    2
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:


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: maven - conventions for integration tests