You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by br...@apache.org on 2006/03/03 08:41:07 UTC
svn commit: r382709 - in /maven/surefire/branches/surefire-testng:
surefire-api/src/main/java/org/apache/maven/surefire/
surefire-api/src/main/java/org/apache/maven/surefire/report/
surefire-api/src/main/java/org/apache/maven/surefire/suite/ surefire-a...
Author: brett
Date: Thu Mar 2 23:41:05 2006
New Revision: 382709
URL: http://svn.apache.org/viewcvs?rev=382709&view=rev
Log:
[MSUREFIRE-23] clean up abstract test set
Modified:
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/AbstractTestSet.java
maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java
maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java
Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java?rev=382709&r1=382708&r2=382709&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java Thu Mar 2 23:41:05 2006
@@ -249,11 +249,4 @@
{
return bundle.getString( key );
}
-
-/* TODO: should catch this elsewhere
- if ( Modifier.isAbstract( testClass.getModifiers() ) )
- {
- return null;
- }
-*/
}
Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java?rev=382709&r1=382708&r2=382709&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java Thu Mar 2 23:41:05 2006
@@ -43,7 +43,7 @@
super.testSetStarting( report );
String message = "Running " + report.getName();
- if ( !report.getGroup().equals( report.getName() ) )
+ if ( report.getGroup() != null && !report.getName().equals( report.getGroup() ) )
{
message = message + " (of " + report.getGroup() + ")";
}
Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java?rev=382709&r1=382708&r2=382709&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java Thu Mar 2 23:41:05 2006
@@ -25,6 +25,7 @@
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -76,33 +77,34 @@
{
String className = tests[i];
- SurefireTestSet testSet;
+ Class testClass;
try
{
- testSet = createTestSet( className, classLoader );
+ testClass = classLoader.loadClass( className );
}
catch ( ClassNotFoundException e )
{
throw new TestSetFailedException( "Unable to create test class '" + className + "'", e );
}
- if ( testSets.containsKey( testSet.getName() ) )
+ if ( !Modifier.isAbstract( testClass.getModifiers() ) )
{
- throw new TestSetFailedException( "Duplicate test set '" + testSet.getName() + "'" );
- }
+ SurefireTestSet testSet = createTestSet( testClass );
- testSets.put( testSet.getName(), testSet );
+ if ( testSets.containsKey( testSet.getName() ) )
+ {
+ throw new TestSetFailedException( "Duplicate test set '" + testSet.getName() + "'" );
+ }
+ testSets.put( testSet.getName(), testSet );
- totalTests += testSet.getTestCount();
+ totalTests += testSet.getTestCount();
+ }
}
return Collections.unmodifiableMap( testSets );
}
- protected abstract Object[] createConstructorArguments( String className );
-
- protected abstract SurefireTestSet createTestSet( String className, ClassLoader classLoader )
- throws ClassNotFoundException;
+ protected abstract SurefireTestSet createTestSet( Class testClass );
public void execute( ReporterManager reporterManager, ClassLoader classLoader )
throws ReporterException, TestSetFailedException
Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/AbstractTestSet.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/AbstractTestSet.java?rev=382709&r1=382708&r2=382709&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/AbstractTestSet.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/AbstractTestSet.java Thu Mar 2 23:41:05 2006
@@ -16,17 +16,12 @@
* limitations under the License.
*/
-import org.apache.maven.surefire.report.ReportEntry;
-import org.apache.maven.surefire.report.ReporterManager;
-
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
/**
- * @todo trim it up. Those implementing don't need any of this except for discoverTestMethods, getName and isValidMethod
* @todo bring back other helpers and put in a separate package
*/
public abstract class AbstractTestSet
@@ -36,181 +31,9 @@
protected List testMethods;
- private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
-
- public void execute( ReporterManager reportManager, ClassLoader loader )
- throws TestSetFailedException
- {
- if ( reportManager == null )
- {
- throw new NullPointerException( "reportManager is null" );
- }
-
- executeTestMethods( reportManager );
- }
-
- protected void executeTestMethods( ReporterManager reportManager )
- {
- if ( reportManager == null )
- {
- throw new NullPointerException( "reportManager is null" );
- }
-
- if ( testMethods == null )
- {
- discoverTestMethods();
- }
-
- boolean abort = false;
-
- for ( int i = 0; i < testMethods.size() && !abort; ++i )
- {
- abort = executeTestMethod( (Method) testMethods.get( i ), EMPTY_OBJECT_ARRAY, reportManager );
- }
- }
-
- protected boolean executeTestMethod( Method method, Object[] args, ReporterManager reportManager )
- {
- if ( method == null || args == null || reportManager == null )
- {
- throw new NullPointerException();
- }
-
- String userFriendlyMethodName = method.getName() + '(';
-
- if ( args.length != 0 )
- {
- userFriendlyMethodName += "Reporter";
- }
-
- userFriendlyMethodName += ')';
-
- ReportEntry report = new ReportEntry( this, getTestName( userFriendlyMethodName ), getClass().getName() );
-
- reportManager.testStarting( report );
-
- try
- {
- setUpFixture();
- }
- catch ( Exception e )
- {
-/* TODO
- // Treat any exception from setUpFixture as a failure of the test.
- String rawString = Surefire.getResourceString( "setupFixtureFailed" );
-
- MessageFormat msgFmt = new MessageFormat( rawString );
-
- Object[] stringArgs = {method.getName()};
-
- String stringToPrint = msgFmt.format( stringArgs );
-
- report = new ReportEntry( this, getTestName( userFriendlyMethodName ), stringToPrint, e );
-
- reportManager.testFailed( report );
-*/
-
- // A return value of true indicates to this class's executeTestMethods
- // method that it should abort and not attempt to execute
- // any other test methods. The other caller of this method,
- // TestRerunner.rerun, ignores this return value, because it is
- // only running one test.
- return true;
- }
-
- // Make sure that tearDownFixture
- try
- {
- method.invoke( getTestClassInstance(), args );
-
- report = new ReportEntry( this, getTestName( userFriendlyMethodName ), this.getClass().getName() );
-
- reportManager.testSucceeded( report );
- }
- catch ( InvocationTargetException ite )
- {
- Throwable t = ite.getTargetException();
-
- String msg = t.getMessage();
-
- if ( msg == null )
- {
- msg = t.toString();
- }
-
- report = new ReportEntry( this, getTestName( userFriendlyMethodName ), msg, t );
-
- reportManager.testFailed( report );
- // Don't return here, because tearDownFixture should be called even
- // if the test method throws an exception.
- }
- catch ( Exception e )
- {
- String msg = e.getMessage();
-
- if ( msg == null )
- {
- msg = e.toString();
- }
-
- report = new ReportEntry( this, getTestName( userFriendlyMethodName ), msg, e );
-
- reportManager.testFailed( report );
- // Don't return here, because tearDownFixture should be called even
- // if the test method throws an exception.
- }
-
- try
- {
- tearDownFixture();
- }
- catch ( Exception e )
- {
-
-/* TODO
- // Treat any exception from tearDownFixture as a failure of the test.
- String rawString = Surefire.getResourceString( "cleanupFixtureFailed" );
-
- MessageFormat msgFmt = new MessageFormat( rawString );
-
- Object[] stringArgs = {method.getName()};
-
- String stringToPrint = msgFmt.format( stringArgs );
-
- report = new ReportEntry( this, getTestName( userFriendlyMethodName ), stringToPrint, e );
-
- reportManager.testFailed( report );
-*/
-
- // A return value of true indicates to this class's executeTestMethods
- // method that it should abort and not attempt to execute
- // any other test methods. The other caller of this method,
- // TestRerunner.rerun, ignores this return value, because it is
- // only running one test.
- return true;
- }
-
- // A return value of false indicates to this class's executeTestMethods
- // method that it should keep plowing ahead and invoke more test methods.
- // The other caller of this method,
- // TestRerunner.rerun, ignores this return value, because it is
- // only running one test.
- return false;
- }
-
public String getName()
{
- return getClass().getName();
- }
-
- public String getTestName( String testMethodName )
- {
- if ( testMethodName == null )
- {
- throw new NullPointerException( "testMethodName is null" );
- }
-
- return getClass() + "." + testMethodName;
+ return getTestClass().getName();
}
public int getTestCount()
@@ -221,27 +44,11 @@
return testMethods.size();
}
- public void setUpFixture()
- throws Exception
- {
- }
-
- public void tearDownFixture()
- throws Exception
- {
- }
-
protected Class getTestClass()
{
return getClass();
}
- protected Object getTestClassInstance()
- throws IllegalAccessException, InstantiationException
- {
- return this;
- }
-
protected void discoverTestMethods()
{
if ( testMethods == null )
@@ -254,7 +61,7 @@
{
Method m = methods[i];
- if ( isValidMethod( m ) )
+ if ( isValidTestMethod( m ) )
{
String simpleName = m.getName();
@@ -274,11 +81,7 @@
}
}
- // ----------------------------------------------------------------------
- // Batteries
- // ----------------------------------------------------------------------
-
- public static boolean isValidMethod( Method m )
+ public static boolean isValidTestMethod( Method m )
{
boolean isInstanceMethod = !Modifier.isStatic( m.getModifiers() );
Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java?rev=382709&r1=382708&r2=382709&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java Thu Mar 2 23:41:05 2006
@@ -35,14 +35,8 @@
super( basedir, includes, excludes );
}
- protected Object[] createConstructorArguments( String className )
+ protected SurefireTestSet createTestSet( Class testClass )
{
- return new Object[]{JUnitTestSet.class.getName(), new Object[]{className}};
- }
-
- protected SurefireTestSet createTestSet( String className, ClassLoader classLoader )
- throws ClassNotFoundException
- {
- return new JUnitTestSet( className, classLoader );
+ return new JUnitTestSet( testClass );
}
}
Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java?rev=382709&r1=382708&r2=382709&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java Thu Mar 2 23:41:05 2006
@@ -68,12 +68,6 @@
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
- public JUnitTestSet( String testClassName, ClassLoader classLoader )
- throws ClassNotFoundException
- {
- testClass = classLoader.loadClass( testClassName );
- }
-
public JUnitTestSet( Class testClass )
{
if ( testClass == null )
@@ -169,23 +163,9 @@
}
else
{
- try
- {
- countTestCasesMethod = testClass.getMethod( COUNT_TEST_CASES_METHOD, EMPTY_CLASS_ARRAY );
- }
- catch ( NoSuchMethodException e )
- {
- countTestCasesMethod = null; // for clarity
- }
+ countTestCasesMethod = testClass.getMethod( COUNT_TEST_CASES_METHOD, EMPTY_CLASS_ARRAY );
- try
- {
- runMethod = testClass.getMethod( RUN_METHOD, new Class[]{testResultClass} );
- }
- catch ( NoSuchMethodException e )
- {
- runMethod = null; // for clarity
- }
+ runMethod = testClass.getMethod( RUN_METHOD, new Class[]{testResultClass} );
}
}
@@ -227,15 +207,7 @@
throw new TestSetFailedException( "Class is not a JUnit TestCase", e );
}
- // TODO: why do we accept runMethod == null? That means it doesn't extend TestCase
- if ( runMethod != null )
- {
- executeJUnit( reportManager, loader );
- }
- else
- {
- super.execute( reportManager, loader );
- }
+ executeJUnit( reportManager, loader );
}
private void executeJUnit( ReporterManager reportManager, ClassLoader classLoader )
@@ -282,18 +254,9 @@
{
try
{
- int testCount;
- if ( countTestCasesMethod != null )
- {
- Integer integer = (Integer) countTestCasesMethod.invoke( testObject, EMPTY_CLASS_ARRAY );
+ Integer integer = (Integer) countTestCasesMethod.invoke( testObject, EMPTY_CLASS_ARRAY );
- testCount = integer.intValue();
- }
- else
- {
- testCount = super.getTestCount();
- }
- return testCount;
+ return integer.intValue();
}
catch ( IllegalAccessException e )
{
@@ -307,11 +270,6 @@
{
throw new TestSetFailedException( testObject.getClass().getName(), e.getTargetException() );
}
- }
-
- public String getName()
- {
- return testClass.getName();
}
private Constructor getTestConstructor( Class testClass )
Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java?rev=382709&r1=382708&r2=382709&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java Thu Mar 2 23:41:05 2006
@@ -38,14 +38,8 @@
// TODO
}
- protected Object[] createConstructorArguments( String className )
+ protected SurefireTestSet createTestSet( Class testClass )
{
- return new Object[]{TestNGTestSet.class.getName(), new Object[]{className}};
- }
-
- protected SurefireTestSet createTestSet( String className, ClassLoader classLoader )
- throws ClassNotFoundException
- {
- return new TestNGTestSet( className );
+ return new TestNGTestSet( testClass );
}
}
Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java?rev=382709&r1=382708&r2=382709&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java Thu Mar 2 23:41:05 2006
@@ -50,16 +50,9 @@
* Creates a new test testset that will process the class being
* passed in to determine the testing configuration.
*/
- public TestNGTestSet( String testClass )
- throws ClassNotFoundException
+ public TestNGTestSet( Class testClass )
{
- if ( testClass == null )
- {
- throw new NullPointerException( "testClass is null" );
- }
-
- // TODO: broken. the test class uses testng from the project tree, but we use the other one. Annotations aren't found.
- this.testClass = getClass().getClassLoader().loadClass( testClass );
+ this.testClass = testClass;
/*
this.testSourceDirectory = testSourceDirectory;
@@ -83,7 +76,7 @@
{
Method m = methods[i];
- if ( isValidMethod( m ) )
+ if ( isValidTestMethod( m ) )
{
String simpleName = m.getName();
@@ -149,11 +142,6 @@
//actually runs all the tests
List result = testNG.runSuitesLocally();
// nbTests += result.size(); TODO
- }
-
- public String getName()
- {
- return testClass.getName();
}
private static IAnnotationFinder getAnnotationFinder()