Bug 102632 - [JUnit] Support for JUnit 4.
Summary: [JUnit] Support for JUnit 4.
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 enhancement with 8 votes (vote)
Target Milestone: 3.2 RC2   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
: 128376 (view as bug list)
Depends on:
Blocks: 129035
  Show dependency tree
 
Reported: 2005-07-04 05:23 EDT by Ringo De Smet CLA
Modified: 2020-08-30 17:16 EDT (History)
19 users (show)

See Also:


Attachments
Proposed patches and tests for JUnit 4 support in Eclipse (89.27 KB, application/octet-stream)
2005-09-26 15:50 EDT, David Saff CLA
no flags Details
The tests for JUnit, which go with the previous patch (182.25 KB, application/octet-stream)
2005-09-26 15:51 EDT, David Saff CLA
no flags Details
Updated patches and tests for JUnit 4 in Eclipse (92.52 KB, application/octet-stream)
2005-10-10 22:08 EDT, David Saff CLA
no flags Details
Updated tests for JUnit (189.79 KB, application/octet-stream)
2005-10-10 22:10 EDT, David Saff CLA
no flags Details
Patches for existing JUnit-facing Eclipse plug-ins (43.76 KB, application/octet-stream)
2006-01-27 16:08 EST, David Saff CLA
no flags Details
New plug-ins for handling junit 4 (247.80 KB, application/octet-stream)
2006-01-27 16:08 EST, David Saff CLA
no flags Details
Patches for existing plug-ins, version 2006 Feb 06 (62.25 KB, application/zip)
2006-02-06 03:08 EST, David Saff CLA
no flags Details
New plug-ins for handling junit 4, version 2006 Feb 06 (540.59 KB, application/zip)
2006-02-06 03:09 EST, David Saff CLA
no flags Details
Patches for existing plug-ins, version 2006 Feb 06b (63.77 KB, application/zip)
2006-02-06 23:41 EST, David Saff CLA
no flags Details
New plug-ins for handling junit 4, version 2006 Feb 06b (247.83 KB, application/zip)
2006-02-06 23:42 EST, David Saff CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ringo De Smet CLA 2005-07-04 05:23:47 EDT
Hello,

I'm probably very fast with entering this feature request, but with JUnit 4 in
the works, I would like to verify that JUnit 4 will get integrated into Eclipse
very soon.

JUnit 4, requiring Java 5, uses Java annotations to mark test methods, setup and
teardown methods and test decorators. This will probably have an influence on
how Eclipse should collect all test methods as well as on the integrated Eclipse
JUnit test runner.

Ringo
Comment 1 Dirk Baeumer CLA 2005-07-04 09:55:03 EDT
Eclipse 3.1 can already execute JUnit 4 tests. Have you tried it ;-). All you
have to do is to use the test execution adapter provided by JUnit 4 inside the
suite method.
Comment 2 Elliotte Rusty Harold CLA 2005-08-23 11:31:24 EDT
The adapter based integration is imperfect. It works for whole classes but not
indiivdual methods. That is,  the tests in 
org.junit.samples.ListTest by selecting the class in Package Explorer 
and choosing Run As JUnit test from the context menu. The tests pass. Cool!

However, if instead of selecting the entire test I just select one test 
method; e.g. contains(); then the test fails like so:

junit.framework.AssertionFailedError: Could not create test 'contains'
	at junit.framework.Assert.fail(Assert.java:51)
	at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner$2.runTest(RemoteTestRunner.java:557)
	at junit.framework.TestCase.runBare(TestCase.java:130)
	at junit.framework.TestResult$1.protect(TestResult.java:110)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	at junit.framework.TestResult.run(TestResult.java:113)
	at junit.framework.TestCase.run(TestCase.java:120)
	at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

I don't suggest working on this until JUnit 4 is released, but once it is this
is worth addressing. 
Comment 3 Dirk Baeumer CLA 2005-08-23 11:46:55 EDT
We are working on a full JUnit4 integration for 3.2.
Comment 4 David Saff CLA 2005-09-26 15:50:44 EDT
Created attachment 27534 [details]
Proposed patches and tests for JUnit 4 support in Eclipse

This is an interim post of the patches I'm proposing to introduce full JUnit 4
support into Eclipse, with the option of running against a JUnit 3 / Java 1.4
runtime as well.  The current status:

Currently the following work for both JUnit 3 and 4:

1) Run tests by manually creating a test configuration
2) Navigate to failure method
3) Rerun failing test from failure or hierarchy tabs
4) Run all tests in a container by manually creating a test configuration
5) Run plug-in tests

This is half done, but currently broken:

6) Run As > JUnit test correctly runs either JUnit 3 or 4 tests

These work in JUnit 3, but not yet JUnit 4:

7) Rerun button from JUnit view
9) Stop button from JUnit view
10) Compare values in a comparison failure

I've broken this in JUnit 3, and it doesn't work yet in JUnit 4:

8) Rerun failures first

This doesn't work yet:

11) Automatically run all JUnit 3 and JUnit 4 tests in a project simultaneously


And I know exactly the refactoring that has to happen for this, but haven't
done it yet:

12) Do not require 1.5 JVM when running only JUnit 3 tests.

I've been planning all along with the assumption that there will be some users
that have only a 1.4 JVM, and therefore can only use JUnit 3.8.  This will
require splitting up the junit.runtime plug-in, which makes patching more
complicated, so I've been putting it off for now.

To get started trying this out, unzip the attached file, and look at
eclipse-junit4-root/README.  This is not for the faint of heart--these are big
patches against CVS, with some legwork to get them working.  However, feedback
is appreciated.  I'll try to keep further updates coming every couple days as
items get checked off the list above.  Unfortunately, the JMock binaries I've
been using are too big to post, so you'll have to get them from subversion, as
described in the README file.  I'll post the tests as a different attachment.
Comment 5 David Saff CLA 2005-09-26 15:51:15 EDT
Created attachment 27535 [details]
The tests for JUnit, which go with the previous patch
Comment 6 David Saff CLA 2005-10-10 22:08:43 EDT
Created attachment 28100 [details]
Updated patches and tests for JUnit 4 in Eclipse

New status:

Currently the following work for both JUnit 3 and 4:

1) Run tests by manually creating a test configuration
2) Navigate to failure method
3) Rerun failing test from failure or hierarchy tabs
4) Run all tests in a container by manually creating a test configuration
5) Run plug-in tests
6) Run As > JUnit test correctly runs either JUnit 3 or 4 tests

These work, but do not have tests in JUnit 4:

7) Rerun button from JUnit view
10) Compare values in a comparison failure

This partially works:

9) Stop button from JUnit view (only stops between classes, not between
methods)

I've broken this in JUnit 3, and it doesn't work yet in JUnit 4:

8) Rerun failures first

This doesn't work yet:

11) Automatically run all JUnit 3 and JUnit 4 tests in a project simultaneously


And I know exactly the refactoring that has to happen for this, but haven't
done it yet:

12) Do not require 1.5 JVM when running only JUnit 3 tests.
Comment 7 David Saff CLA 2005-10-10 22:10:56 EDT
Created attachment 28101 [details]
Updated tests for JUnit
Comment 8 Dirk Baeumer CLA 2005-11-04 10:26:01 EST
Hi David, thanks a lot for the patches. 

Unfortunatelly we didn't find any time to look at them in the M3 time frame
(lots of us were on vacation). 

Markus Keller will be our new man for JUnit. Our idea is to have JUnit4
integration and some sort of test model for Eclips itself. I have asked Markus
to look at this during the M4 time frame and he will look at the patches you
have provided so far.

Markus, a small tip: the patches are zips which contain a lot of unneccessary
stuff. The interesting file are the patch files in the root of 'eclipse-junit4-root'
Comment 9 David Saff CLA 2005-11-21 15:50:28 EST
Dirk,

Sorry, I thought I had added myself to the CC list when I posted the patches.  I'm happy to devote more time to this, and I look forward to feedback from Markus soon.
Comment 10 Markus Keller CLA 2005-11-23 06:46:18 EST
David: I'm currently reorganizing the jdt.junit plugin to create a model for test sessions. I had a look at your patches and I think it's easier for me to make the model first and then adapt to JUnit 4.
As soon as I'm done with the model, I'll integrate JUnit 4 support from your patches.
Comment 11 David Saff CLA 2005-11-29 20:48:37 EST
Markus,

I'd be happy to refit my patches to the new JUnit-with-model.  Would that be useful?
Comment 12 David Saff CLA 2006-01-27 16:08:02 EST
Created attachment 33736 [details]
Patches for existing JUnit-facing Eclipse plug-ins
Comment 13 David Saff CLA 2006-01-27 16:08:34 EST
Created attachment 33737 [details]
New plug-ins for handling junit 4
Comment 14 David Saff CLA 2006-01-27 16:14:51 EST
I've attached the latest patches.  The chief advances are:

1) The patches are clean, without svn or CVS junk
2) The patches are against Markus' JUnit w/ Model patch, sent to me in mid-December
3) They work with (and contain) the CVS version of JUnit 4 from this morning, which has changed rather drastically from before.
4) Classes annotated with @RunWith are recognized as JUnit 4 test classes

Known problems:
1) Run with failed first has not yet been fixed
2) Does not automatically run all JUnit 3 and JUnit 4 tests from a project simultaneously
3) Still requires JRE 1.5 even for JUnit 3 tests.

Fixes for these are coming soon.  Please provide feedback--it would be great to have Eclipse support JUnit 4 at the same time that JUnit 4 goes final.
Comment 15 David Saff CLA 2006-02-06 03:08:24 EST
Created attachment 34180 [details]
Patches for existing plug-ins, version 2006 Feb 06
Comment 16 David Saff CLA 2006-02-06 03:09:50 EST
Created attachment 34181 [details]
New plug-ins for handling junit 4, version 2006 Feb 06
Comment 17 David Saff CLA 2006-02-06 03:11:56 EST
This latest version has a couple fixes.  It runs with the updated JUnit 4 API.  Most importantly, each test kind can now specify its own runtime classpath, meaning that JUnit 3 tests can run on top of old JRE's, and not require the JUnit 4 jars.
Comment 18 David Saff CLA 2006-02-06 23:41:43 EST
Created attachment 34258 [details]
Patches for existing plug-ins, version 2006 Feb 06b

Against HEAD, with proper copyright headers
Comment 19 David Saff CLA 2006-02-06 23:42:42 EST
Created attachment 34259 [details]
New plug-ins for handling junit 4, version 2006 Feb 06b

With proper headers, compiles against HEAD
Comment 20 Markus Keller CLA 2006-02-17 08:54:59 EST
*** Bug 128376 has been marked as a duplicate of this bug. ***
Comment 21 David Saff CLA 2006-02-17 10:47:36 EST
A note to Juergen, who posted bug 128376:

If you use JUnit 4's backwards compatibility, you can run your JUnit 4 tests in Eclipse.  Add to your suite or test class:

public static Test suite() {
   return new JUnit4Adapter(ThisClass.class);
}

Let me know if this works for you.  Thanks.
Comment 22 Juergen Zimmermann CLA 2006-02-18 02:16:58 EST
> Add to your suite or test class:
> public static Test suite() {
>    return new JUnit4Adapter(ThisClass.class);
> }
> Let me know if this works for you.

Yes, this works fine.
Comment 23 Daniel Spiewak CLA 2006-03-02 16:07:15 EST
This is great stuff.  Are we looking at 3.2 M6 as a timeframe for expecting this?
Comment 24 Markus Keller CLA 2006-03-03 04:21:08 EST
> Are we looking at 3.2 M6 as a timeframe for expecting this?

Yes, that's the plan. Sorry that I forgot to set the milestone. We're sorting out some last legal and technical issues before this can be released.
Comment 25 Markus Keller CLA 2006-03-28 05:32:49 EST
We now got legal approvement for adding JUnit4, but it's unfortunately too late for M6. Moving to RC1.
Comment 26 Chris Beams CLA 2006-04-09 15:06:10 EDT
It was my understanding that M6 marked 'feature freeze' for the 3.2 release.  Is it really possible that Junit4 support will be rolled into RC1?  Wouldn't that constitute a new feature?
Comment 27 Martin Aeschlimann CLA 2006-04-10 05:03:39 EDT
As stated in the end game plan, new features for RC1 need PMC approval. I'll do that request as soon as we ready.
Comment 28 Christian Hauser CLA 2006-04-16 17:02:24 EDT
Sorry for asking questions within this bug, but is there a short description on how to use JUnit 4 within Eclipse 3.2. I've just tried Eclipse 3.2RC1 and I still have to extend my class from TestCase and need to provide a suite() method that returns a new JUnit4TestAdapter. Otherwise I cannot run my test class as JUnit test.
Comment 29 Erich Gamma CLA 2006-04-21 04:53:02 EDT
(In reply to comment #27)
> As stated in the end game plan, new features for RC1 need PMC approval. I'll do
> that request as soon as we ready.
> 
getting JUnit4 support into the RC has PMC approval
Comment 30 Martin Aeschlimann CLA 2006-04-21 13:02:55 EDT
released updated JUnit 4 wizard, new JUnit classpath container, updated quick fixes > 20060421
Comment 31 John Arthorne CLA 2006-04-24 14:52:38 EDT
(Various API additions in org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageOne)
Comment 32 Markus Keller CLA 2006-04-26 10:37:03 EDT
Released support for JUnit4 > 20060426. Launch Configurations can now specify a JUnit4 Test Loader.

Please open new bug reports if you find problems with the solution in the upcoming builds.
Comment 33 Markus Keller CLA 2006-04-26 10:38:01 EDT
Grrr... sorry for the spam. Setting to FIXED.
Comment 34 Carsten Hammer CLA 2020-08-30 17:16:08 EDT
With this code we now have a codemetrics warning:

Bug: Useless object stored in variable input of method org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageOne.performBuildpathConfiguration(Object)

Our analysis shows that this object is useless. It's created and modified, but its value never go outside of the method or produce any side-effect. Either there is a mistake and object was intended to be used or it can be removed.

This analysis rarely produces false-positives. Common false-positive cases include:

- This object used to implicitly throw some obscure exception.

- This object used as a stub to generalize the code.

- This object used to hold strong references to weak/soft-referenced objects.



else if ("c".equals(data)) { // open compliance //$NON-NLS-1$
			String buildPath= BUILD_PATH_PAGE_ID;
			String complianceId= COMPLIANCE_PAGE_ID;
			Map input= new HashMap();
			input.put(KEY_NO_LINK, Boolean.TRUE);
			PreferencesUtil.createPropertyDialogOn(getShell(), javaProject, buildPath, new String[] { buildPath, complianceId  }, data).open();
		}

commit 6358a4e5c327b982f65559899249f361069a4c3c
Author: Martin Aeschlimann <maeschli> 2006-04-20 16:52:27