diff --git a/surefire/.cvsignore b/surefire/.cvsignore new file mode 100644 index 00000000..8eeb0ff8 --- /dev/null +++ b/surefire/.cvsignore @@ -0,0 +1,7 @@ +target +velocity.log +maven.log +.classpath +.project +*.ipr +*.iws diff --git a/surefire/plugin.jelly b/surefire/plugin.jelly new file mode 100644 index 00000000..35396f4f --- /dev/null +++ b/surefire/plugin.jelly @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No test source files to compile. + + + + + + + + + + + ${testRunner.setProject(pom)} + ${testRunner.execute()} + + + + + + + + + + + + + + No tests to run. + + + + + + + + + + + + No tests to run. + + + + + + + + + + + + + No tests to run. + + + + + + + [deprecated] please use the test:single goal instead + + + + + + + [deprecated] please use the test:match goal instead + + + + + + Used by eclipse to drag in test plugin context + + + + + + + + + + + + + + + + + + + + + + + diff --git a/surefire/plugin.properties b/surefire/plugin.properties new file mode 100644 index 00000000..fa4cd8e4 --- /dev/null +++ b/surefire/plugin.properties @@ -0,0 +1,14 @@ +# ------------------------------------------------------------------- +# P L U G I N P R O P E R T I E S +# ------------------------------------------------------------------- +# JUnit test plugin. +# ------------------------------------------------------------------- + +maven.junit.fork = no +maven.junit.dir = ${basedir} +maven.junit.usefile = true +maven.junit.printSummary=true +maven.test.dest = ${maven.build.dir}/test-classes +maven.test.reportsDirectory = ${maven.build.dir}/test-reports +maven.test.skip = false +maven.junit.jvmargs= \ No newline at end of file diff --git a/surefire/project.properties b/surefire/project.properties new file mode 100644 index 00000000..b3a3ca54 --- /dev/null +++ b/surefire/project.properties @@ -0,0 +1,7 @@ +# ------------------------------------------------------------------- +# P R O J E C T P R O P E R T I E S +# ------------------------------------------------------------------- +maven.xdoc.date=left +## maven.xdoc.version=${pom.currentVersion} +maven.license.licenseFile=${basedir}/../../../LICENSE.txt + diff --git a/surefire/project.xml b/surefire/project.xml new file mode 100644 index 00000000..83ec5ae5 --- /dev/null +++ b/surefire/project.xml @@ -0,0 +1,47 @@ + + + + ../project.xml + 3 + maven-surefire-plugin + maven-surefire-plugin + Maven SureFire Plug-in + 1.0-SNAPSHOT + + Run JUnit tests + http://maven.apache.org/reference/plugins/surefire/ + /www/maven.apache.org/reference/plugins/surefire/ + + scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven/src/plugins-build/surefire/ + http://cvs.apache.org/viewcvs/maven/src/plugins-build/test/ + + + + + + junit + junit + 3.8.1 + + + maven + test-runner + 1.4 + + + maven + maven-model + 2.0-alpha-2 + + + maven + maven-project + 2.0-alpha-2 + + + plexus + plexus-utils + 1.0-beta-1 + + + diff --git a/surefire/src/main/org/apache/maven/test/IsolatedClassLoader.class b/surefire/src/main/org/apache/maven/test/IsolatedClassLoader.class new file mode 100644 index 00000000..ed2c8875 Binary files /dev/null and b/surefire/src/main/org/apache/maven/test/IsolatedClassLoader.class differ diff --git a/surefire/src/main/org/apache/maven/test/IsolatedClassLoader.java b/surefire/src/main/org/apache/maven/test/IsolatedClassLoader.java new file mode 100644 index 00000000..085fddf6 --- /dev/null +++ b/surefire/src/main/org/apache/maven/test/IsolatedClassLoader.java @@ -0,0 +1,59 @@ +package org.apache.maven.test; + +import java.net.URLClassLoader; +import java.net.URL; + +/** + * + * + * @author Jason van Zyl + * + * @version $Id: IsolatedClassLoader.java,v 1.1 2004/01/09 16:22:59 jvanzyl Exp $ + */ +public class IsolatedClassLoader + extends URLClassLoader +{ + private ClassLoader parent = ClassLoader.getSystemClassLoader(); + + public IsolatedClassLoader() + { + super( new URL[0], null ); + } + + public void addURL( URL url ) + { + super.addURL( url ); + } + + public synchronized Class loadClass( String className ) + throws ClassNotFoundException + { + Class c = findLoadedClass( className ); + + ClassNotFoundException ex = null; + + if ( c == null ) + { + try + { + c = findClass( className ); + } + catch ( ClassNotFoundException e ) + { + ex = e; + + if ( parent != null ) + { + c = parent.loadClass( className ); + } + } + } + + if ( c == null ) + { + throw ex; + } + + return c; + } +} diff --git a/surefire/src/main/org/apache/maven/test/TestRunnerBooter.class b/surefire/src/main/org/apache/maven/test/TestRunnerBooter.class new file mode 100644 index 00000000..506bc627 Binary files /dev/null and b/surefire/src/main/org/apache/maven/test/TestRunnerBooter.class differ diff --git a/surefire/src/main/org/apache/maven/test/TestRunnerBooter.java b/surefire/src/main/org/apache/maven/test/TestRunnerBooter.java new file mode 100644 index 00000000..aa66d1b8 --- /dev/null +++ b/surefire/src/main/org/apache/maven/test/TestRunnerBooter.java @@ -0,0 +1,109 @@ +package org.apache.maven.test; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.apache.maven.project.Project; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.Iterator; +import java.util.List; +import java.lang.reflect.Method; + +/** + * A command line based tool to run tests. + *
+ * java junit.textui.TestRunner [-wait] TestCaseClass
+ * 
+ * TestRunner expects the name of a TestCase class as argument. + * If this class defines a static suite method it + * will be invoked and the returned test is run. Otherwise all + * the methods starting with "test" having no arguments are run. + *

+ * When the wait command line argument is given TestRunner + * waits until the users types RETURN. + *

+ * TestRunner prints a trace as the tests are executed followed by a + * summary at the end. + */ +public class TestRunnerBooter +{ + private Project project; + + public void setProject( Project project ) + { + this.project = project; + } + + public void execute() + throws Exception + { + // maven.build.dest + // maven.test.dest + // maven.build.dest + // maven.test.dest + + IsolatedClassLoader classLoader = new IsolatedClassLoader(); + + File basedir = project.getFile().getParentFile(); + + System.setProperty( "basedir", basedir.getPath() ); + + Thread.currentThread().setContextClassLoader( classLoader ); + + classLoader.addURL( new File ( "/home/jvanzyl/maven-repo-local/junit/jars/junit-3.8.1.jar" ).toURL() ); + + classLoader.addURL( new File ( "/tmp/test-runner-1.4.jar" ).toURL() ); + + classLoader.addURL( new File( basedir, "target/classes/" ).toURL() ); + + classLoader.addURL( new File( basedir, "target/test-classes/" ).toURL() ); + + processDependencies( project, classLoader ); + + Class testRunnerClass = classLoader.loadClass( "org.apache.maven.test.TestRunner" ); + + Object testRunner = testRunnerClass.newInstance(); + + Method m = testRunnerClass.getMethod( "runTestClasses", new Class[] { + File.class, + List.class, + List.class, + ClassLoader.class } ); + + m.invoke( testRunner, new Object[]{ + basedir, + project.getBuild().getUnitTest().getIncludes(), + project.getBuild().getUnitTest().getExcludes(), + classLoader, + } ); + } + + // We need to deal with populating a plugin classloader with its requirements. + private void processDependencies( Project project, IsolatedClassLoader classLoader ) + throws MalformedURLException + { + if ( project.getArtifacts() == null ) + { + return; + } + + for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + + Dependency dependency = artifact.getDependency(); + + // Only add compile type dependencies to classloader + if ( dependency.getType().equals( "jar" ) ) + { + // We have the jar and the classloader to push it into so + // lets do it! + if ( artifact.exists() ) + { + classLoader.addURL( artifact.getFile().toURL() ); + } + } + } + } +} diff --git a/surefire/src/surefire-runner/.cvsignore b/surefire/src/surefire-runner/.cvsignore new file mode 100644 index 00000000..7244964b --- /dev/null +++ b/surefire/src/surefire-runner/.cvsignore @@ -0,0 +1,5 @@ +target +velocity.log +maven.log +.classpath +.project diff --git a/surefire/src/surefire-runner/project.xml b/surefire/src/surefire-runner/project.xml new file mode 100644 index 00000000..991bc4f6 --- /dev/null +++ b/surefire/src/surefire-runner/project.xml @@ -0,0 +1,30 @@ + + + + 3 + maven + surefire-runner + surefire-runner + Surefire Test Runner + 1.0-SNAPSHOT + + Run JUnit tests + http://maven.apache.org/reference/plugins/surefire-runner + /www/maven.apache.org/reference/plugins/surefire-runner + + scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven/src/plugins-build/surefire-runner + http://cvs.apache.org/viewcvs/maven/src/plugins-build/surefire-runner + + + + + + junit + junit + 3.8.1 + + + + src/main + + diff --git a/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenJUnitTestSuite.java b/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenJUnitTestSuite.java new file mode 100644 index 00000000..c9026b5a --- /dev/null +++ b/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenJUnitTestSuite.java @@ -0,0 +1,368 @@ +package org.apache.maven.test; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestResult; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Enumeration; +import java.util.Vector; + +/** + * A TestSuite is a Composite of Tests. + * It runs a collection of test cases. Here is an example using + * the dynamic test definition. + *

+ * TestSuite suite= new TestSuite();
+ * suite.addTest(new MathTest("testAdd"));
+ * suite.addTest(new MathTest("testDivideByZero"));
+ * 
+ * Alternatively, a TestSuite can extract the tests to be run automatically. + * To do so you pass the class of your TestCase class to the + * TestSuite constructor. + *
+ * TestSuite suite= new TestSuite(MathTest.class);
+ * 
+ * This constructor creates a suite with all the methods + * starting with "test" that take no arguments. + * + * @see junit.framework.Test + */ +public class MavenJUnitTestSuite + implements Test +{ + private Vector fTests = new Vector( 10 ); + + private String fName; + + private Class junitTest = null; + + private Class testResultClass = null; + + /** + * Constructs an empty TestSuite. + */ + public MavenJUnitTestSuite() + { + } + + /** + * Constructs a TestSuite from the given class with the given name. + */ + public MavenJUnitTestSuite( Class theClass ) + { + this( theClass, ClassLoader.getSystemClassLoader() ); + } + + /** + * Constructs a TestSuite from the given class. Adds all the methods + * starting with "test" as test cases to the suite. + * Parts of this method was written at 2337 meters in the H�ffih�tte, + * Kanton Uri + */ + public MavenJUnitTestSuite( final Class theClass, ClassLoader classLoader ) + { + try + { + junitTest = classLoader.loadClass( "junit.framework.Test" ); + + testResultClass = classLoader.loadClass( "junit.framework.TestResult" ); + } + catch ( ClassNotFoundException e ) + { + } + + fName = theClass.getName(); + try + { + getTestConstructor( theClass ); // Avoid generating multiple error messages + } + catch ( NoSuchMethodException e ) + { + addTest( warning( "Class " + theClass.getName() + " has no public constructor TestCase(String name) or TestCase()" ) ); + return; + } + + if ( !Modifier.isPublic( theClass.getModifiers() ) ) + { + addTest( warning( "Class " + theClass.getName() + " is not public" ) ); + return; + } + + Class superClass = theClass; + Vector names = new Vector(); + + while ( junitTest.isAssignableFrom( superClass ) ) + { + Method[] methods = superClass.getDeclaredMethods(); + for ( int i = 0; i < methods.length; i++ ) + { + addTestMethod( methods[i], names, theClass ); + } + superClass = superClass.getSuperclass(); + } + + if ( fTests.size() == 0 ) + { + addTest( warning( "No tests found in " + theClass.getName() ) ); + } + } + + /** + * Constructs an empty TestSuite. + */ + public MavenJUnitTestSuite( String name ) + { + setName( name ); + } + + /** + * Adds a test to the suite. + */ + public void addTest( Object test ) + { + fTests.addElement( test ); + } + + /** + * Adds the tests from the given class to the suite + */ + public void addTestSuite( Class testClass ) + { + addTest( new MavenJUnitTestSuite( testClass ) ); + } + + private void addTestMethod( Method m, Vector names, Class theClass ) + { + String name = m.getName(); + + if ( names.contains( name ) ) + { + return; + } + + if ( !isPublicTestMethod( m ) ) + { + if ( isTestMethod( m ) ) + { + addTest( warning( "Test method isn't public: " + m.getName() ) ); + } + return; + } + + names.addElement( name ); + + addTest( createTest( theClass, name ) ); + } + + /** + * ...as the moon sets over the early morning Merlin, Oregon + * mountains, our intrepid adventurers type... + */ + static public Object createTest( Class theClass, String name ) + { + Constructor constructor; + + try + { + constructor = getTestConstructor( theClass ); + } + catch ( NoSuchMethodException e ) + { + return warning( "Class " + theClass.getName() + " has no public constructor TestCase(String name) or TestCase()" ); + } + Object test; + try + { + if ( constructor.getParameterTypes().length == 0 ) + { + test = constructor.newInstance( new Object[0] ); + + if ( test instanceof TestCase ) + { + ( (TestCase) test ).setName( name ); + } + } + else + { + test = constructor.newInstance( new Object[]{name} ); + } + } + catch ( InstantiationException e ) + { + return ( warning( "Cannot instantiate test case: " + name + " (" + exceptionToString( e ) + ")" ) ); + } + catch ( InvocationTargetException e ) + { + return ( warning( "Exception in constructor: " + name + " (" + exceptionToString( e.getTargetException() ) + ")" ) ); + } + catch ( IllegalAccessException e ) + { + return ( warning( "Cannot access test case: " + name + " (" + exceptionToString( e ) + ")" ) ); + } + + return test; + } + + /** + * Converts the stack trace into a string + */ + private static String exceptionToString( Throwable t ) + { + StringWriter stringWriter = new StringWriter(); + PrintWriter writer = new PrintWriter( stringWriter ); + t.printStackTrace( writer ); + return stringWriter.toString(); + + } + + /** + * Counts the number of test cases that will be run by this test. + */ + public int countTestCases() + { + int count = 0; + for ( Enumeration e = tests(); e.hasMoreElements(); ) + { + Test test = (Test) e.nextElement(); + count = count + test.countTestCases(); + } + return count; + } + + /** + * Gets a constructor which takes a single String as + * its argument or a no arg constructor. + */ + public static Constructor getTestConstructor( Class theClass ) + throws NoSuchMethodException + { + Class[] args = {String.class}; + + try + { + return theClass.getConstructor( args ); + } + catch ( NoSuchMethodException e ) + { + // fall through + } + return theClass.getConstructor( new Class[0] ); + } + + private boolean isPublicTestMethod( Method m ) + { + return isTestMethod( m ) && Modifier.isPublic( m.getModifiers() ); + } + + private boolean isTestMethod( Method m ) + { + String name = m.getName(); + Class[] parameters = m.getParameterTypes(); + Class returnType = m.getReturnType(); + return parameters.length == 0 && name.startsWith( "test" ) && returnType.equals( Void.TYPE ); + } + + /** + * Runs the tests and collects their result in a TestResult. + */ + public void run( TestResult result ) + { + for ( Enumeration e = tests(); e.hasMoreElements(); ) + { + if ( result.shouldStop() ) + { + break; + } + + Object test = e.nextElement(); + + runTest( test, result ); + } + } + + public void runTest( Object test, TestResult result ) + { + try + { + Method m = test.getClass().getMethod( "run", new Class[] { testResultClass } ); + + m.invoke( test, new Object[] { result } ); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + + /** + * Returns the test at the given index + */ + public Test testAt( int index ) + { + return (Test) fTests.elementAt( index ); + } + + /** + * Returns the number of tests in this suite + */ + public int testCount() + { + return fTests.size(); + } + + /** + * Returns the tests as an enumeration + */ + public Enumeration tests() + { + return fTests.elements(); + } + + /** + */ + public String toString() + { + if ( getName() != null ) + return getName(); + return super.toString(); + } + + /** + * Sets the name of the suite. + * @param name The name to set + */ + public void setName( String name ) + { + fName = name; + } + + /** + * Returns the name of the suite. Not all + * test suites have a name and this method + * can return null. + */ + public String getName() + { + return fName; + } + + /** + * Returns a test which will fail and log a warning message. + */ + private static Test warning( final String message ) + { + return new TestCase( "warning" ) + { + protected void runTest() + { + fail( message ); + } + }; + } +} diff --git a/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenTestSuiteLoader.java b/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenTestSuiteLoader.java new file mode 100644 index 00000000..b07d3983 --- /dev/null +++ b/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenTestSuiteLoader.java @@ -0,0 +1,33 @@ +package org.apache.maven.test; + +import junit.runner.TestSuiteLoader; + +/** + * + * + * @author Jason van Zyl + * + * @version $Id: MavenTestSuiteLoader.java,v 1.1 2004/01/09 16:23:01 jvanzyl Exp $ + */ +public class MavenTestSuiteLoader + implements TestSuiteLoader +{ + private ClassLoader classLoader; + + public MavenTestSuiteLoader( ClassLoader classLoader ) + { + this.classLoader = classLoader; + } + + public Class load( String className ) + throws ClassNotFoundException + { + return classLoader.loadClass( className ); + } + + public Class reload( Class clazz ) + throws ClassNotFoundException + { + return clazz; + } +} diff --git a/surefire/src/surefire-runner/src/main/org/apache/maven/test/ResultPrinter.java b/surefire/src/surefire-runner/src/main/org/apache/maven/test/ResultPrinter.java new file mode 100644 index 00000000..ad85f262 --- /dev/null +++ b/surefire/src/surefire-runner/src/main/org/apache/maven/test/ResultPrinter.java @@ -0,0 +1,143 @@ +package org.apache.maven.test; + +import java.io.PrintStream; +import java.text.NumberFormat; +import java.util.Enumeration; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import junit.framework.TestFailure; +import junit.framework.TestListener; +import junit.framework.TestResult; +import junit.runner.BaseTestRunner; + +public class ResultPrinter implements TestListener +{ + PrintStream fWriter; + int fColumn = 0; + + public ResultPrinter( PrintStream writer ) + { + fWriter = writer; + } + + synchronized void print( TestResult result, long runTime, String testName ) + { + //printErrors( result ); + //printFailures( result ); + printFooter( result, runTime, testName ); + } + + protected void printErrors( TestResult result ) + { + printDefects( result.errors(), result.errorCount(), "error" ); + } + + protected void printFailures( TestResult result ) + { + printDefects( result.failures(), result.failureCount(), "failure" ); + } + + protected void printDefects( Enumeration booBoos, int count, String type ) + { + if ( count == 0 ) + { + return; + } + if ( count == 1 ) + { + getWriter().println( "There was " + count + " " + type + ":" ); + } + else + { + getWriter().println( "There were " + count + " " + type + "s:" ); + } + + for ( int i = 1; booBoos.hasMoreElements(); i++ ) + { + printDefect( (TestFailure) booBoos.nextElement(), i ); + } + } + + public void printDefect( TestFailure booBoo, int count ) + { // only public for testing purposes + printDefectHeader( booBoo, count ); + printDefectTrace( booBoo ); + } + + protected void printDefectHeader( TestFailure booBoo, int count ) + { + // I feel like making this a println, then adding a line giving the throwable a chance to print something + // before we get to the stack trace. + getWriter().print( count + ") " + booBoo.failedTest() ); + } + + protected void printDefectTrace( TestFailure booBoo ) + { + getWriter().print( BaseTestRunner.getFilteredTrace( booBoo.trace() ) ); + } + + protected void printFooter( TestResult result, long runtime, String testName ) + { + getWriter().println( " [funit] Running " + testName ); + + getWriter().println( " [funit] Tests run: " + result.runCount() + + ", Failures: " + result.failureCount() + + ", Errors: " + result.errorCount() + + ", Time elapsed: " + elapsedTimeAsString( runtime ) + " sec" ); + + printErrors( result ); + printFailures( result ); + } + + /** + * Returns the formatted string of the elapsed time. + * Duplicated from BaseTestRunner. Fix it. + */ + protected String elapsedTimeAsString( long runTime ) + { + return NumberFormat.getInstance().format( (double) runTime / 1000 ); + } + + public PrintStream getWriter() + { + return fWriter; + } + + /** + * @see junit.framework.TestListener#addError(Test, Throwable) + */ + public void addError( Test test, Throwable t ) + { + getWriter().print( "E" ); + } + + /** + * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError) + */ + public void addFailure( Test test, AssertionFailedError t ) + { + getWriter().print( "F" ); + } + + /** + * @see junit.framework.TestListener#endTest(Test) + */ + public void endTest( Test test ) + { + } + + /** + * @see junit.framework.TestListener#startTest(Test) + */ + public void startTest( Test test ) + { + getWriter().print( "." ); + if ( fColumn++ >= 40 ) + { + getWriter().println(); + fColumn = 0; + } + } + +} diff --git a/surefire/src/surefire-runner/src/main/org/apache/maven/test/TestRunner.java b/surefire/src/surefire-runner/src/main/org/apache/maven/test/TestRunner.java new file mode 100644 index 00000000..08e48156 --- /dev/null +++ b/surefire/src/surefire-runner/src/main/org/apache/maven/test/TestRunner.java @@ -0,0 +1,215 @@ +package org.apache.maven.test; + +import junit.framework.Test; +import junit.framework.TestResult; +import junit.framework.TestSuite; +import junit.runner.BaseTestRunner; +import junit.runner.TestSuiteLoader; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.io.PrintStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Iterator; +import java.util.List; + +/** + * A command line based tool to run tests. + *
+ * java junit.textui.TestRunner [-wait] TestCaseClass
+ * 
+ * TestRunner expects the name of a TestCase class as argument. + * If this class defines a static suite method it + * will be invoked and the returned test is run. Otherwise all + * the methods starting with "test" having no arguments are run. + *

+ * When the wait command line argument is given TestRunner + * waits until the users types RETURN. + *

+ * TestRunner prints a trace as the tests are executed followed by a + * summary at the end. + */ +public class TestRunner + extends BaseTestRunner +{ + private ResultPrinter resultPrinter; + + public static final int SUCCESS_EXIT = 0; + + public static final int FAILURE_EXIT = 1; + + public static final int EXCEPTION_EXIT = 2; + + private static final String FS = System.getProperty( "file.separator" ); + + public TestRunner() + { + this( System.out ); + } + + public TestRunner( PrintStream writer ) + { + this( new ResultPrinter( writer ) ); + } + + public TestRunner( ResultPrinter printer ) + { + resultPrinter = printer; + } + + private ClassLoader classLoader; + private List includes; + private List excludes; + private File basedir; + + public void runTestClasses( File basedir, List includes, List excludes, ClassLoader classLoader ) + throws Exception + { + this.basedir = basedir; + this.includes = includes; + this.excludes = excludes; + this.classLoader = classLoader; + + DirectoryScanner scanner = new DirectoryScanner(); + + scanner.setBasedir( new File( basedir, "target/test-classes" ) ); + + String[] incs = new String[includes.size()]; + + for ( int i = 0; i < incs.length; i++ ) + { + incs[i] = StringUtils.replace( (String) includes.get( i ), "java", "class" ); + } + + scanner.setIncludes( incs ); + + String[] excls = new String[excludes.size() + 1]; + + for ( int i = 0; i < excls.length - 1; i++ ) + { + excls[i] = StringUtils.replace( (String) excludes.get( i ), "java", "class" ); + } + + // Exclude inner classes + + excls[excludes.size()] = "**/*$*"; + + scanner.setExcludes( excls ); + + scanner.scan(); + + String[] files = scanner.getIncludedFiles(); + + String s; + + for ( int i = 0; i < files.length; i++ ) + { + s = files[i]; + + s = s.substring( 0, s.indexOf( "." ) ); + + s = StringUtils.replace( s, FS, "." ); + + Class clazz = null; + + try + { + clazz = classLoader.loadClass( s ); + } + catch( ClassNotFoundException e ) + { + System.out.println( "Can't find className = " + s ); + + continue; + } + + TestResult result = run( clazz, s ); + + if ( result.errorCount() > 0 || result.failureCount() > 0 ) + { + failures = "true"; + } + } + } + + private String failures = "false"; + + public String failures() + { + return failures; + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + public TestResult run( Class testClass, String testName ) + { + return run( new TestSuite( testClass ), testName ); + + //return run( new MavenJUnitTestSuite( testClass, classLoader ), testName ); + } + + public TestResult run( Test test, String testName ) + { + TestRunner runner = new TestRunner(); + + return runner.doRun( test, testName ); + } + + public TestSuiteLoader getLoader() + { + return new MavenTestSuiteLoader( classLoader ); + } + + public void testFailed( int status, Test test, Throwable t ) + { + } + + public void testStarted( String testName ) + { + } + + public void testEnded( String testName ) + { + } + + protected TestResult createTestResult() + { + return new TestResult(); + } + + public TestResult doRun( Test suite, String testName ) + { + TestResult result = createTestResult(); + + long startTime = System.currentTimeMillis(); + + suite.run( result ); + + long endTime = System.currentTimeMillis(); + + long runTime = endTime - startTime; + + resultPrinter.print( result, runTime, testName ); + + return result; + } + + protected void runFailed( String message ) + { + System.err.println( message ); + + System.exit( FAILURE_EXIT ); + } + + public void setPrinter( ResultPrinter printer ) + { + resultPrinter = printer; + } + + +} diff --git a/surefire/src/surefire-runner/surefire-runner.ipr b/surefire/src/surefire-runner/surefire-runner.ipr new file mode 100644 index 00000000..804db6b7 --- /dev/null +++ b/surefire/src/surefire-runner/surefire-runner.ipr @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/surefire/src/surefire-runner/surefire-runner.iws b/surefire/src/surefire-runner/surefire-runner.iws new file mode 100644 index 00000000..56f67bcc --- /dev/null +++ b/surefire/src/surefire-runner/surefire-runner.iws @@ -0,0 +1,704 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/surefire/swap-plugin b/surefire/swap-plugin new file mode 100755 index 00000000..dc2217e6 --- /dev/null +++ b/surefire/swap-plugin @@ -0,0 +1,13 @@ +#!/bin/sh + +rm -rf target + +maven jar:jar + +( cd ~/.maven/plugins ; rm -rf maven-test-plugin* ) + +rm -f ~/maven/plugins/maven-test-plugin*.jar + +cp target/maven-test-plugin*.jar ~/maven/plugins + +rm -f ~/.maven/plugins/*.cache diff --git a/surefire/xdocs/.cvsignore b/surefire/xdocs/.cvsignore new file mode 100644 index 00000000..cb6131bb --- /dev/null +++ b/surefire/xdocs/.cvsignore @@ -0,0 +1 @@ +stylesheets diff --git a/surefire/xdocs/changes.xml b/surefire/xdocs/changes.xml new file mode 100644 index 00000000..8f8c4fb7 --- /dev/null +++ b/surefire/xdocs/changes.xml @@ -0,0 +1,50 @@ + + + + Changes + dIon Gillard + + + + + + Apply MAVEN-309. Reorganise classpaths so that it's test, build, dependencies + and then JUnit + + + You can now specify whether the source (java) or classes (class) files + are searched when using the test plugin via the property: + maven.test.search.classdir. It defaults to use (java) to preserve + backwards compatibilty. Using (class) allows you to work with alternative + languages that compile to bytecode like + Groovy + + + Check if unitTest tag is present in pom before copy resources. + + + + + Add jvmarg support for junit. + Add properties documentation. + + + + + Fixed classpath for test:ui, test:single and test:match goals. + + + Added xmlapis and xerces to project dependencies as per MAVEN-106 + bug report + + + + + The test plugin now works again if the project has not + tests defined. The introduction of the <test:test-resources> + goal had broken this feature. + + + + + diff --git a/surefire/xdocs/goals.xml b/surefire/xdocs/goals.xml new file mode 100644 index 00000000..5c2e2c53 --- /dev/null +++ b/surefire/xdocs/goals.xml @@ -0,0 +1,52 @@ + + + + + Maven test Plug-in Goals + dIon Gillard + + + + + test + Test the application + + + test:compile + Compile the TestCases and TestSuites + + + test:match + Execute all the tests matching the given 'testmatch' variable + + + test:match-test + [deprecated] please use the test:match goal instead + + + test:prepare-filesystem + Create the needed directory structure + + + test:single + Execute a single test defined using the 'testcase' variable + + + test:single-test + [deprecated] please use the test:single goal instead + + + test:test + Test the application + + + test:test-resources + Copy any resources that must be present for run tests + + + test:ui + Starts the Swing TestRunner front end + + + + \ No newline at end of file diff --git a/surefire/xdocs/index.xml b/surefire/xdocs/index.xml new file mode 100644 index 00000000..b2ee037b --- /dev/null +++ b/surefire/xdocs/index.xml @@ -0,0 +1,16 @@ + + + + + Maven Test Plugin + Jason van Zyl + + + +

+

+ This plug-in provides your basic JUnit testing facilities. +

+
+ + diff --git a/surefire/xdocs/navigation.xml b/surefire/xdocs/navigation.xml new file mode 100644 index 00000000..1f8d81ee --- /dev/null +++ b/surefire/xdocs/navigation.xml @@ -0,0 +1,16 @@ + + + + Maven Test Plugin + + + + + + + + + + + + diff --git a/surefire/xdocs/properties.xml b/surefire/xdocs/properties.xml new file mode 100644 index 00000000..f9bed713 --- /dev/null +++ b/surefire/xdocs/properties.xml @@ -0,0 +1,207 @@ + + + + + Test Properties + Stéphane MOR + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyOptional?Description
maven.junit.forkYes + When using Java 1.4, it may be necessary to fork the JUnit + tests to prevent XML parser issues. The default value is + no. +
maven.junit.dirYes + The directory to invoke the VM in. (ignored if fork is disabled). + The default value is ${basedir}. +
maven.junit.usefileYes + If this value is set to false, JUnit test run details will appear on + the console as the tests are executed. If not, they are stored in + a file in the test-reports directory. The default value + is true. +
maven.junit.printSummaryYes + If this value is set to false, JUnit test run details will not + include test summary information for a suite. Default value is + true. This parameter corresponds to the JUnit Ant + task printSummary attribute. +
maven.test.destYes + Specifies the unit test classes directory. This is the + location where the java classes for the test source + code will be generated to. The default value is + ${maven.build.dir}/test-classes. +
maven.test.skipYes + Set this to 'true' to bypass unit tests entirely. Its use + is NOT RECOMMENDED, but quite convenient on occasion. +
maven.test.failure.ignoreYes + Set this to any value to ignore a failure during testing. + Its use is NOT RECOMMENDED, but quite convenient on occasion. +
maven.test.sourceYes +

+ Provide source compatibility with a specific release +

+

+ Corresponds to the source attribute for the ant + javac + task. +

+
maven.iutest.destYes + Specifies the integration unit test classes directory. + This is the location where the java classes for the + integration unit test source code will be generated to. + The default value is + ${maven.build.dir}/iutest-classes. +
maven.iutest.dirYes + Specifies the integration unit test source directory. + This property should never be overridden as the value is + determined directly from the project descriptor. The + default value is + ${maven.integrationUnitTestSourceDirectory}. +
maven.out.test.dirYes + Specifies the directory where the integration unit testing + is run. The default value is ${build.dir}/iutest. +
maven.webapp.dirYes + Specifies the directory of the web application used to + perform integration unit testing. The default value is + ${iutest.dir}/testapp. +
maven.conf.test.dirYes + Specifies the configuration directory used to build the + web application used for integration unit testing. The + default value is ${iutest.dir}/cactus. +
maven.tomcat.homeYes + Specifies your local Tomcat installation directory. + The default value is ${tdk.home}. If + ${tdk.home} is not specified in your + ${user.home}/build.properties, you should set + this property. This is used for the integration unit + testing. +
maven.test.portYes + Specifies the port that Tomcat will use for integration + unit testing. The default value is 8192. +
maven.junit.jvmargsYes + If fork is enabled, additional parameters may be passed to the new VM. + You can specify some args separate by space. + Each arg is describe in sub properties. + Sample : + + +
maven.junit.syspropertiesYes + Use this property elements to specify system properties required + by the class. These properties will be made available to the VM during + the execution of the test (either Maven's VM or the forked VM, if fork is enabled). + You can specify system properties separate by space. + Each properties is describe in sub properties. + Sample : + + +
maven.test.search.classdirYes + Use this property to specify that JUnit should search the test classes directory + rather than the source directory. This allows for test cases to be written in other + languages such as Groovy which generate bytecode that can then be used by this plugin. + Sample : + + +
+
+ +