• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

maven - conventions for integration tests

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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/
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:


 
Die Fledermaus does not fear such a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic