Bug 38811 - Support JUnit 4
Summary: Support JUnit 4
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Optional Tasks (show other bugs)
Version: 1.6.5
Hardware: All All
: P2 major (vote)
Target Milestone: 1.7.0
Assignee: Ant Notifications List
URL:
Keywords:
: 40289 40406 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-02-28 21:50 UTC by Jesse Glick
Modified: 2006-09-03 21:22 UTC (History)
4 users (show)



Attachments
Manual test case (3.13 KB, text/plain)
2006-02-28 22:06 UTC, Jesse Glick
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2006-02-28 21:50:36 UTC
Currently Ant's <junit> is designed for JUnit 3.x. It is possible to run JUnit 4
tests (i.e. those which use annotations and do not extend TestCase) only if you
pollute your test code with the otherwise unnecessary

  public static Test suite() {
    return new JUnit4TestAdapter(ThisTest.class);
  }

Otherwise, running under Ant 1.6.5 you just get

junit.framework.AssertionFailedError: No tests found in MyTest

Ant can be patched to always accept JUnit 3.x tests, and to also accept "pure"
JUnit 4.x tests when junit-4.0.jar is in the classpath. Note that in the latter
case you _must_ be running on JDK 5 or later; even the "legacy" classes use the
JDK 5 classfile format.

Not terribly complicated but involves a bit of fine-tuning since the two
frameworks have some subtle differences. Patch tries to accomplish:

1. No change in behavior when using junit-3.x.jar.

2. Use junit-4.0.jar to run JUnit 3.x tests transparently in compatibility mode.
Use junit-4.0.jar to run JUnit 4.x tests transparently (currently also in
compatibility mode, to keep the task relatively simple). No user configuration
or change in <junit> task signature.

3. Treat Assert.* failures as real failures, not errors.

4. Use the @Test-annotated method name as the test case name in the expected way.
Comment 1 Jesse Glick 2006-02-28 22:06:42 UTC
Created attachment 17809 [details]
Manual test case

Checks successes, failures, and errors in 3-type and 4-type test classes.
Output ought to look similar.
Comment 2 Jesse Glick 2006-02-28 22:07:35 UTC
revision 381780
Comment 3 Jesse Glick 2006-03-01 23:11:52 UTC
Tweak in revision 382127.
Comment 4 Jesse Glick 2006-08-22 23:54:38 UTC
*** Bug 40289 has been marked as a duplicate of this bug. ***
Comment 5 J.M. (Martijn) Kruithof 2006-09-04 04:22:21 UTC
*** Bug 40406 has been marked as a duplicate of this bug. ***