maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "manuel aldana (JIRA)" <j...@codehaus.org>
Subject [jira] Created: (SUREFIRE-458) alternative test-class scanner (by type filter)
Date Thu, 14 Feb 2008 11:56:34 GMT
alternative test-class scanner (by type filter) 
------------------------------------------------

                 Key: SUREFIRE-458
                 URL: http://jira.codehaus.org/browse/SUREFIRE-458
             Project: Maven Surefire
          Issue Type: Improvement
          Components: plugin
    Affects Versions: 2.4.1
            Reporter: manuel aldana


hi, 

currently test filtering is done by using the <include> directive, which includes test-classes
by file name pattern. this approach is sometimes a bit annoying for namings of classes are
unreliable. test data classes are sometimes named like TestDataForXXX or XXXDataForTest so
they are included to testsuite too.

a better approach would be to scan test classes by the type. currently we are using gsbase-test-suite
scanner to accomplish this. it would be cool if this kind of scanner would be included in
surefire-plugin, so it is not neccessary to implement such a collector for each project.

following code as example (scans for test-classes which are concrete):
{code:java title=Test-class Scanner}
import java.lang.reflect.Modifier;

import com.gargoylesoftware.base.testing.RecursiveTestSuite;
import com.gargoylesoftware.base.testing.TestFilter;

import junit.framework.Test;

/** @author manuel aldana, aldana@gmx.de */
public class TestCaseCollector {

	/** @return Testsuite, which returns all concrete Test-classes */
	public static Test suite() throws Exception {
		return new RecursiveTestSuite("target/test-classes", new TestFilter() {
			public boolean accept(Class clazz) {
				if (isConcreteTestCase(clazz))
					return true;
				return false;
			}
		});
	}

	private static boolean isConcreteTestCase(Class clazz) {
		if (isAbstractClass(clazz))
			// it is assumed, that abstract classes have no superclasses which are concrete test classes
			return false;
		if (clazz.getSuperclass().getName().equals("java.lang.Object"))
			return false;
		if (clazz.getSuperclass().getName().equals("junit.framework.TestCase"))
			return true;
		// recurse to parents
		return isConcreteTestCase(clazz.getSuperclass());
	}

	private static boolean isAbstractClass(Class clazz) {
		if (Modifier.isAbstract(clazz.getModifiers()))
			return true;
		return false;
	}

}
{code}



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message