Bug 140290 - [JUnit] JUnit 4 code assist to import static org.junit.Assert.*
Summary: [JUnit] JUnit 4 code assist to import static org.junit.Assert.*
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: All All
: P4 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 152123
Blocks:
  Show dependency tree
 
Reported: 2006-05-04 23:25 EDT by David Saff CLA
Modified: 2012-05-22 08:48 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Saff CLA 2006-05-04 23:25:14 EDT
When a new JUnit 4 test class is created, it would be great if it added at the top:

import static org.junit.Assert.*;

This is usually necessary to do anything productive, and Eclipse currently does not provide a quick-fix to import statics.
Comment 1 Dani Megert CLA 2006-05-05 07:21:15 EDT
The Assert is already added by the wizard:
  if (isJUnit4()) { 
      imports.addStaticImport("org.junit.Assert", "*", false);

but gets removed by NewTestCaseWizardPageOne.removeUnusedImports() which is private.

According to Martin we could use the import template but he's not sure whether to fix this bug at all because it would generate a CU with a warning or even an error if unused imports is set to 'error'.

A possible solution would be to add a checkbox to the wizard which lets the user choose the import.

Setting target milestone to RC4 so that Martin can decide next week.

Comment 2 Martin Aeschlimann CLA 2006-05-10 14:10:33 EDT
not for 3.2. Note that we have a quick fix that can add the static import. Just no code assist.
Comment 3 Martin Aeschlimann CLA 2006-07-28 11:52:28 EDT
See bug 152123 for suggestion of general code assist support for references with static imports
Comment 4 Dani Megert CLA 2007-01-15 04:02:54 EST
The JUnit wizard could now ask the user whether to add Assert to the favorties and update the PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS preference accordingly.
Comment 5 Martin Aeschlimann CLA 2007-01-15 05:01:46 EST
I was hoping to add this to project settings rather than workspace settings. What are the plans here?
 
Comment 6 Dani Megert CLA 2007-01-15 05:02:49 EST
No projects settings for now.
Comment 7 Lars Vogel CLA 2008-11-19 01:50:12 EST
If I remove import static org.junit.Assert.assertTrue; from the imports Cntrl+Shirt + O (Organize Imports) will not create this import. 

Is this problem related to this, or shall I open a separate bug report?
Comment 8 Dani Megert CLA 2008-11-19 03:26:37 EST
>Is this problem related to this, or shall I open a separate bug report?
Not related, see bug 94078.
Comment 9 Lars Vogel CLA 2012-05-10 14:07:57 EDT
@Dani: I think this works since I while. I suggest to close this bug.
Comment 10 Dani Megert CLA 2012-05-22 08:48:44 EDT
Works for me using 3.8 RC1.