Bug 40289 - The JUnit optional task does not support JUnit 4.1 (JDK 1.5)
Summary: The JUnit optional task does not support JUnit 4.1 (JDK 1.5)
Status: RESOLVED DUPLICATE of bug 38811
Alias: None
Product: Ant
Classification: Unclassified
Component: Optional Tasks (show other bugs)
Version: 1.6.5
Hardware: All other
: P2 normal (vote)
Target Milestone: 1.7.0
Assignee: Ant Notifications List
URL:
Keywords: JDK1.5
Depends on:
Blocks:
 
Reported: 2006-08-18 22:04 UTC by Sonya Quist
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***