You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Dan Fabulich (JIRA)" <ji...@codehaus.org> on 2008/02/15 22:41:28 UTC
[jira] Updated: (SUREFIRE-458) alternative test-class scanner (by
type filter)
[ http://jira.codehaus.org/browse/SUREFIRE-458?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Dan Fabulich updated SUREFIRE-458:
----------------------------------
Fix Version/s: 2.x
> 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
> Fix For: 2.x
>
>
> 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