<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>andrewmccall.com &#187; Integration testing</title>
	<atom:link href="http://andrewmccall.com/tag/integration-testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewmccall.com</link>
	<description>If you want to know what I think...</description>
	<lastBuildDate>Wed, 02 Jun 2010 20:24:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Integration testing in maven &#8211; With Maven, Cargo, httpunit and Selenium</title>
		<link>http://andrewmccall.com/2008/09/integration-testing-in-maven-with-maven-cargo-httpunit-and-selenium/</link>
		<comments>http://andrewmccall.com/2008/09/integration-testing-in-maven-with-maven-cargo-httpunit-and-selenium/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 11:00:07 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[cargo]]></category>
		<category><![CDATA[httpunit]]></category>
		<category><![CDATA[Integration testing]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[surefire]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[unit testing]]></category>
		<category><![CDATA[Unit Tests]]></category>

		<guid isPermaLink="false">http://andrewmccall.com/?p=83</guid>
		<description><![CDATA[I&#8217;ve been trying to figure this out for months, and thought it should have been simple. All I wanted to ...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to figure this out for months, and thought it should have been simple. All I wanted to do was write a set of unit tests to test my java code, have them run whenever I hit test. Next I wanted to have a set of HTTP Unit, Selenium or similar tests run to test that the actual application is working when it&#8217;s built and deployed to a container using the cargo plugin.</p>
<p>I didn&#8217;t really want to have a separate project to do this because it seemed like a massive pain in the ass to maintain the whole thing. I didn&#8217;t see any reason why it shouldn&#8217;t be easy with Maven either &#8211; it does have a phase for integration-tests already.</p>
<p>My first try looked good to me:</p>
<p> </p>
<p><code></p>
<pre>...
&lt;build>
    ...
    &lt;plugins>
        ...
        &lt;plugin>
            &lt;groupId>org.apache.maven.plugins&lt;/groupId>
            &lt;artifactId>maven-surefire-plugin&lt;/artifactId>
            &lt;configuration>
                &lt;excludes>
                    &lt;exclude>**/integration/**&lt;/exclude>
                &lt;/excludes>
            &lt;/configuration>
            &lt;executions>
                &lt;execution>
                    &lt;id>integrationtest&lt;/id>
                    &lt;phase>integration-test&lt;/phase>
                    &lt;goals>
                        &lt;goal>test&lt;/goal>
                    &lt;/goals>
                    &lt;configuration>
                        &lt;excludes>
                            &lt;exclude>none&lt;/exclude>
                        &lt;/excludes>
                        &lt;includes>
                            &lt;include>**/integration/**/*Test*.java&lt;/include>
                            &lt;include>**/integration/**/*Test.java&lt;/include>
                            &lt;include>**/integration/**/*TestCase.java&lt;/include>
                        &lt;/includes>
                    &lt;/configuration>
                &lt;/execution>
            &lt;/executions>
        &lt;/plugin>
        ...
    &lt;/plugins>
    ...
&lt;/build>
...</pre>
<p></code></p>
<p> </p>
<p>I tried to run the tests, but unfortunately when it gets to the second round of tests &#8211; which should run my integration tests &#8211; it runs the same sets of as it ran the first time. I tried adding the <code>combine.children="append"</code> attribute to the includes, and excludes but that didn&#8217;t work either. Finally I came across a source file <a href="http://plexus.codehaus.org/plexus-utils/xref/org/codehaus/plexus/util/xml/Xpp3Dom.html">XppDom</a>, part of plexus which maven uses. XppDom allowed the combine.children attribute as well as another I haven&#8217;t seen mentioned anywhere else <code>childMergeOverride</code>. I added that instead and it worked!</p>
<p> </p>
<p><code></p>
<pre>...
&lt;build>
    ...
    &lt;plugins>
        ...
        &lt;plugin>
            &lt;groupId>org.apache.maven.plugins&lt;/groupId>
            &lt;artifactId>maven-surefire-plugin&lt;/artifactId>
            &lt;configuration>
                &lt;excludes>
                    &lt;exclude>**/integration/**&lt;/exclude>
                &lt;/excludes>
            &lt;/configuration>
            &lt;executions>
                &lt;execution>
                    &lt;id>integrationtest&lt;/id>
                    &lt;phase>integration-test&lt;/phase>
                    &lt;goals>
                        &lt;goal>test&lt;/goal>
                    &lt;/goals>
                    &lt;configuration>
                        &lt;excludes childMergeOverride="true">
                            &lt;exclude>none&lt;/exclude>
                        &lt;/excludes>
                        &lt;includes childMergeOverride="true">
                            &lt;include>**/integration/**/*Test*.java&lt;/include>
                            &lt;include>**/integration/**/*Test.java&lt;/include>
                            &lt;include>**/integration/**/*TestCase.java&lt;/include>
                        &lt;/includes>
                    &lt;/configuration>
                &lt;/execution>
            &lt;/executions>
        &lt;/plugin>
        ...
    &lt;/plugins>
    ...
&lt;/build>
...</pre>
<p></code></p>
<p> </p>
<p> </p>
<h2>Setting it up for Cargo</h2>
<p>I&#8217;ve done this on a few projects, the first was a project that built a series of taglibs which are used across a number of applications. The release for the project is a jar so I have a separate test web-app structure in <code>${baseDir}/src/test/web-app</code>.  The code for generating this war looks like this:</p>
<p> </p>
<p><code></p>
<pre>...
&lt;build>
    ...
    &lt;plugins>
        ...
        &lt;plugin>
            &lt;groupId>org.apache.maven.plugins&lt;/groupId>
            &lt;artifactId>maven-war-plugin&lt;/artifactId>
            &lt;executions>
                &lt;execution>
                    &lt;id>generate-test-war&lt;/id>
                    &lt;phase>pre-integration-test&lt;/phase>
                    &lt;goals>
                        &lt;goal>war&lt;/goal>
                    &lt;/goals>
                &lt;/execution>
            &lt;/executions>
            &lt;configuration>
                &lt;warSourceDirectory>${basedir}/src/test/webapp&lt;/warSourceDirectory>
                &lt;warName>${project.artifactId}-test&lt;/warName>
                &lt;webappDirectory>${basedir}/target/${project.artifactId}-test&lt;/webappDirectory>
                &lt;primaryArtifact>false&lt;/primaryArtifact>
            &lt;/configuration>
        &lt;/plugin>
        ...
    &lt;/plugins>
    ...
&lt;/build>
...</pre>
<p></code></p>
<p> </p>
<p>During the pre-integration-test phase the above simple generates a test war. If you&#8217;re project is a web-app and it already generates a war you can skip the above as one will be generated for you already.</p>
<p>The next step for was then to get Cargo to deploy the application:</p>
<p> </p>
<p><code></p>
<pre>...
&lt;build>
    ...
    &lt;plugins>
        ...
        &lt;plugin>
            &lt;groupId>org.codehaus.cargo&lt;/groupId>
            &lt;artifactId>cargo-maven2-plugin&lt;/artifactId>
            &lt;configuration>
                &lt;wait>false&lt;/wait>
                &lt;container>
                    &lt;containerId>tomcat5x&lt;/containerId>
                    &lt;zipUrlInstaller>
                        &lt;url>${integrationtests.tomcatURL}&lt;/url>
                        &lt;installDir>${installDir}&lt;/installDir>
                    &lt;/zipUrlInstaller>
                    &lt;output>
                        ${project.build.directory}/tomcat5x.log
                    &lt;/output>
                    &lt;log>${project.build.directory}/cargo.log&lt;/log>
                &lt;/container>
                &lt;configuration>
                    &lt;home>
                        ${project.build.directory}/tomcat5x/container
                    &lt;/home>
                    &lt;properties>
                        &lt;cargo.logging>high&lt;/cargo.logging>
                        &lt;cargo.servlet.port>8080&lt;/cargo.servlet.port>
                    &lt;/properties>
                &lt;/configuration>
            &lt;/configuration>
            &lt;executions>
                &lt;execution>
                    &lt;id>start-container&lt;/id>
                    &lt;phase>pre-integration-test&lt;/phase>
                    &lt;goals>
                        &lt;goal>start&lt;/goal>
                        &lt;goal>deploy&lt;/goal>
                    &lt;/goals>
                    &lt;configuration>
                        &lt;wait>false&lt;/wait>
                        &lt;deployer>
                            &lt;deployables>
                                &lt;deployable>
                                    &lt;location>${basedir}/target/${project.artifactId}-test.war&lt;/location>
                                    &lt;type>war&lt;/type>
                                    &lt;pingURL>http://localhost:8080/${project.artifactId}-test/index.html&lt;/pingURL>
                                    &lt;pingTimeout>300000&lt;/pingTimeout>
                                    &lt;properties>
                                        &lt;context>${project.artifactId}-test&lt;/context>
                                    &lt;/properties>
                                &lt;/deployable>
                            &lt;/deployables>
                        &lt;/deployer>
                    &lt;/configuration>
                &lt;/execution>
                &lt;execution>
                    &lt;id>stop-container&lt;/id>
                    &lt;phase>post-integration-test&lt;/phase>
                    &lt;goals>
                        &lt;goal>stop&lt;/goal>
                    &lt;/goals>
                &lt;/execution>
            &lt;/executions>
        &lt;/plugin>
        ...
    &lt;/plugins>
    ...
&lt;/build>
...</pre>
<p></code><br />
Most of this is pretty self explanatory, I try to use parameters to configure as much as I can and try to maintain it in higher level POMs wherever appropriate. This is especially true for the tomcat URL which changes on a regular basis. The seem to post new releases and remove the older ones, and it can be a chore to keep up in multiple projects. You may want to look at the cargo plugin documentation, you can ignore some of what I&#8217;m doing above if you&#8217;re project&#8217;s default artifact (the one package creates) is a web-app. </p>
<p>So there you have it, eventually I got there after a lot of digging. I&#8217;ve been pretty brief in my explanations and have assumed a fairly good understanding of maven. if you have any questions by all means leave a comment and I&#8217;ll do my best to make it clearer.<br />
<h6 class="zemanta-related-title" style="font-size:1em;">Related articles by Zemanta</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://devlicio.us/blogs/casey/archive/2008/10/01/testing-is-not-technically-hard-it-is-hard-because-it-requires-clear-thought-and-understanding.aspx">Testing Is Not Technically Hard, It Is Hard Because It Requires Clear Thought and Understanding</a></li>
<li class="zemanta-article-ul-li"><a href="http://www.sergiutruta.com/2008/01/22/why-do-we-not-write-tests/">Why do we (not) write tests</a></li>
</ul>
<div class="zemanta-pixie" style="margin-top:10px;height:15px"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/f8e533a8-0d07-4f2c-a95f-11a21413e161/" title="Zemified by Zemanta"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_c.png?x-id=f8e533a8-0d07-4f2c-a95f-11a21413e161" alt="Reblog this post [with Zemanta]" style="border:none;float:right"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://andrewmccall.com/2008/09/integration-testing-in-maven-with-maven-cargo-httpunit-and-selenium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
