Hi John,
Author: jdcasey
Date: Sat Feb 7 02:51:21 2009
New Revision: 741834
URL: http://svn.apache.org/viewvc?rev=741834&view=rev
Log:
[MNG-2720] Adding integration test.
Added:
maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-2720/plugin/src/main/java/org/apache/maven/debug/mng2720/ClasspathMojo.java
URL:
http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-2720/plugin/src/main/java/org/apache/maven/debug/mng2720/ClasspathMojo.java?rev=741834&view=auto
==============================================================================
---
maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-2720/plugin/src/main/java/org/apache/maven/debug/mng2720/ClasspathMojo.java
(added)
+++
maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-2720/plugin/src/main/java/org/apache/maven/debug/mng2720/ClasspathMojo.java
Sat Feb 7 02:51:21 2009
@@ -0,0 +1,88 @@
+package org.apache.maven.debug.mng2720;
+
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @goal test
+ * @requiresDependencyResolution compile
+ * @phase package
+ */
+public class ClasspathMojo
+ implements Mojo
+{
+
+ /**
+ * @parameter default-value="${project}"
+ * @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * @parameter default-value="${project.compileClasspathElements}"
+ * @readonly
+ */
+ private List compileClasspathElements;
+
+ private Log log;
+
+ public void execute() throws MojoExecutionException, MojoFailureException
+ {
+ if ( "child2".equals( project.getArtifactId() ) )
+ {
+ boolean found = false;
+ for ( Iterator it = compileClasspathElements.iterator();
it.hasNext(); )
+ {
+ String path = (String) it.next();
+ if ( path.indexOf( "child1-1.jar" ) > -1 )
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if ( !found )
+ {
+ throw new MojoExecutionException( "child1-1.jar dependency artifact
path not found in compile classpath for project: " + project.getId() );
+ }
+ }
+ else if ( "child3".equals( project.getArtifactId() ) )
+ {
+ boolean found = false;
+ for ( Iterator it = compileClasspathElements.iterator();
it.hasNext(); )
+ {
+ String path = (String) it.next();
+ if ( path.indexOf( "child1-1-tests.jar" ) > -1 )
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if ( !found )
+ {
+ throw new MojoExecutionException( "child1-1-tests.jar dependency
artifact path not found in compile classpath for project: " + project.getId() );
+ }
+ }
+
+ log.info( "Tests succeeded." );
+ }
+
When creating new ITs, please try to reuse the existing IT plugins
whenenver possible. The plugin above looks like it can be replaced by
the maven-it-plugin-dependency-resolution. This plugin dumps the class
path and/or artifacts to a simple text file, the verification logic
would then move to the JUnit controller.
That's not to say that ITs should never have their own plugins, but I
think in general we should try to avoid the above approach for the
followng reasons:
Building the plugin requires a bunch of other productions plugins to
work properly. The core ITs shouldn't depend on stuff that is beyond the
scope of the core.
Building the plugin from scratch instead of using a ready-made IT plugin
consumes time. I feel it's a difference if a single test runs in ~2
seconds or > 10 seconds when we consider a scaling factor of 300 tests.
Putting the verification logic inside the plugin makes it harder to
understand the IT. One has to check the JUnit controller, the POMs and
additionally the mojo logic.
Added:
maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-2720/project-hierarchy/child1/src/test/java/org/apache/maven/debug/mng2720/AppTest.java
URL:
http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-2720/project-hierarchy/child1/src/test/java/org/apache/maven/debug/mng2720/AppTest.java?rev=741834&view=auto
==============================================================================
---
maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-2720/project-hierarchy/child1/src/test/java/org/apache/maven/debug/mng2720/AppTest.java
(added)
+++
maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-2720/project-hierarchy/child1/src/test/java/org/apache/maven/debug/mng2720/AppTest.java
Sat Feb 7 02:51:21 2009
@@ -0,0 +1,38 @@
+package org.apache.maven.debug.mng2720;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
To ease understanding of the test and to avoid wasting time on checking
out the ITs and copying their resources, please don't check in files
that are not required for the test.
Thanks
Benjamin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org