Bug 40289

Summary: The JUnit optional task does not support JUnit 4.1 (JDK 1.5)
Product: Ant Reporter: Sonya Quist <sonya_quist>
Component: Optional TasksAssignee: Ant Notifications List <notifications>
Status: RESOLVED DUPLICATE    
Severity: normal Keywords: JDK1.5
Priority: P2    
Version: 1.6.5   
Target Milestone: 1.7.0   
Hardware: All   
OS: other   

Description Sonya Quist 2006-08-18 22:04:49 UTC
JUnit task (JUnitVersionHelper.java) does not support new annotated test cased 
support in JUnit 4.1.

Here is the corrected code:
    public static String getTestCaseName(Test t) {
        if (t instanceof TestCase && testCaseName != null) {
            try {
                return (String) testCaseName.invoke(t, new Object[0]);
            } catch (Throwable e) {
                // ignore
            }
        } else {
            try {
                Method getNameMethod = null;
                try {
                    getNameMethod =
                        t.getClass().getMethod("getName", new Class [0]);
                } catch (NoSuchMethodException e) {
                	try {
                	    getNameMethod = t.getClass().getMethod("name",
                	                                           new Class 
[0]);
	                } catch (NoSuchMethodException e2) {
										
	// support Junit 4.1
                	    getNameMethod = t.getClass().getMethod("toString",
                	                                           new Class 
[0]);
									}
                }
                if (getNameMethod != null
                    && getNameMethod.getReturnType() == String.class) {
                    return (String) getNameMethod.invoke(t, new Object[0]);
                }
            } catch (Throwable e) {
                // ignore
            }
        }
        return "unknown";
    }
Comment 1 Jan Cumps 2006-08-19 06:29:07 UTC
Junit 4 and 4.1 support is available in Ant 1.7.
Ant 1.6.5 supports JUnit 3.8.
Comment 2 Jesse Glick 2006-08-22 23:54:13 UTC
x
Comment 3 Jesse Glick 2006-08-22 23:54:38 UTC
Sort of supports JUnit 4, anyway. See bug #38811 for the details.

*** This bug has been marked as a duplicate of 38811 ***