You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "manuel aldana (JIRA)" <ji...@codehaus.org> on 2008/02/14 12:56:34 UTC

[jira] Created: (SUREFIRE-458) alternative test-class scanner (by type filter)

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

        

[jira] (SUREFIRE-458) alternative test-class scanner (by type filter)

Posted by "Brett Porter (JIRA)" <ji...@codehaus.org>.
     [ https://jira.codehaus.org/browse/SUREFIRE-458?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Brett Porter updated SUREFIRE-458:
----------------------------------

    Fix Version/s:     (was: Backlog)
    
> alternative test-class scanner (by type filter) 
> ------------------------------------------------
>
>                 Key: SUREFIRE-458
>                 URL: https://jira.codehaus.org/browse/SUREFIRE-458
>             Project: Maven Surefire
>          Issue Type: Improvement
>          Components: Maven Surefire Plugin
>    Affects Versions: 2.4.1
>            Reporter: manuel aldana
>            Assignee: Kristian Rosenvold
>
> 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, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Closed: (SUREFIRE-458) alternative test-class scanner (by type filter)

Posted by "Kristian Rosenvold (JIRA)" <ji...@codehaus.org>.
     [ http://jira.codehaus.org/browse/SUREFIRE-458?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kristian Rosenvold closed SUREFIRE-458.
---------------------------------------

    Resolution: Won't Fix
      Assignee: Kristian Rosenvold

Marking this issue won't fix:

This is supported by the "groups" attribute for TestNG, and the corresponding JUnit feature (@Categories support) is SUREFIRE-656. We will not be supporting any additional selection mechanisms since both the major test frameworks now support it.

As an additional info, version 2. 7 now properly detects test classes for all providers, so the wildcard include pattern *.* should be good.

> 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: Maven Surefire Plugin
>    Affects Versions: 2.4.1
>            Reporter: manuel aldana
>            Assignee: Kristian Rosenvold
>             Fix For: Backlog
>
>
> 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

        

[jira] Updated: (SUREFIRE-458) alternative test-class scanner (by type filter)

Posted by "Dan Fabulich (JIRA)" <ji...@codehaus.org>.
     [ 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