Bug 102512 - [JUnit] test method name cut off before (
Summary: [JUnit] test method name cut off before (
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 minor with 5 votes (vote)
Target Milestone: 4.4 M7   Edit
Assignee: Xavier Coulon CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-01 13:55 EDT by Florian Rickert CLA
Modified: 2015-03-18 13:24 EDT (History)
9 users (show)

See Also:
manju656: review+


Attachments
Patch proposal (5.86 KB, application/octet-stream)
2014-02-11 08:44 EST, Xavier Coulon CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Rickert CLA 2005-07-01 13:55:42 EDT
In case my test's name is "log on test (user peter)", the JUnit view will in the 
left window only show "log on test " leaving out the most interesting part.
Comment 1 Dirk Baeumer CLA 2005-07-02 13:40:06 EDT
David, can you have a look please.
Comment 2 David Saff CLA 2005-07-04 05:05:33 EDT
Adjusting name
Comment 3 David Saff CLA 2005-07-04 05:14:39 EDT
This is currently as-designed behavior.  Any text in parentheses is assumed to
be the name of the class in which the test is defined.  A workaround could be to
name the test "log on test [user peter]".  You would get even better Eclipse
integration by not overriding the getName method, and naming your test classes
and methods informationally, like

class LogOnTests
  public void testUserPeter()

This would allow you to double click on failing tests and jump to their source
in the editor.

How important are the parenthesized names to you?
Comment 4 Florian Rickert CLA 2005-07-04 05:32:03 EDT
Actually I read the users from a file, so I can try many possible usernames (not 
all as this would take ages). It's kind of data driven approach so I can't name 
my method testUserPeter(), but testUsers(String name) which my TestSuite 
decompiles into my 
testUsers("Peter"), 
testUsers("James"), 
testUsers("Joe"), 
...
So right now I use the square-brackets workaround, but with parenthesis it looks 
more like the real methods. (square-brackets for arrays, curly braces for 
blocks, ...)

I know this isn't hard-core JUnit, but except the bracket issue it integrates 
great.
Comment 5 Marc Philipp CLA 2012-09-28 05:50:12 EDT
This issue is still present, from 4.11 on Parameterized test will allow specifying a name that potentially may include parentheses so this becomes a JUnit core problem.
Comment 6 Adam Foltzer CLA 2012-10-16 19:41:49 EDT
+1 to Marc's comment. With the new custom names in the Parameterized tests, names can contain arbitrary characters. I'm sure some exotic ones will need to be ruled out, but excluding parentheses and semicolons among others makes it very difficult to appropriately name certain types of tests.
Comment 7 Xavier Coulon CLA 2014-02-10 11:59:05 EST
Hello,

I submitted a patch via Gerrit (https://git.eclipse.org/r/21766) with the following changes:
- Fixed the problem where the test name would be cut after the first open parenthesis.
- Fixed the action that opens the Java Editor at the test method location when the user double-clicks on a TestSuiteElement that corresponds to *single* parameterized test case, otherwise, added an action that expands the TestSuite to show all test cases that belonged to the test suite (ie, the tests that ran with the given parameter data)

Please, let me know if it is OK for you of if it needs more work.

Thanks
Best regards,
Xavier
Comment 8 Dani Megert CLA 2014-02-11 05:06:40 EST
Thanks for the patch. Did you double-check that changing the assumption/design (see comment 2) doesn't break anyone?

Manju, please review, keeping the current design in mind.
Comment 9 Xavier Coulon CLA 2014-02-11 05:10:08 EST
Dani, Manju,

I did some testing on existing JUnit tests and did not find any breakage, but please let me know if I missed something.

Thanks.
Comment 10 Martin Mathew CLA 2014-02-11 06:42:41 EST
(In reply to Xavier Coulon from comment #7)
> Hello,
> 
> I submitted a patch via Gerrit (https://git.eclipse.org/r/21766)

I would prefer to have a patch attached to this bug than via Gerrit. TIA.
Comment 11 Xavier Coulon CLA 2014-02-11 08:44:52 EST
Created attachment 239824 [details]
Patch proposal

Patch proposal (similar to what was submitted via Gerrit).
Comment 12 Xavier Coulon CLA 2014-02-11 08:46:08 EST
Manju,

I attached a patch to this issue, thus I'm reassigning this issue to you now.

Thanks.
Comment 13 Dani Megert CLA 2014-02-11 08:55:20 EST
(In reply to Xavier Coulon from comment #12)
> Manju,
> 
> I attached a patch to this issue, thus I'm reassigning this issue to you now.
> 
> Thanks.

The assignee should always be the one who fixes/d the bug. Manju is marked as reviewer.
Comment 14 Xavier Coulon CLA 2014-02-11 09:25:40 EST
Dani,

Sorry about that, I didn't know I should remain the assignee during the review process.
Comment 15 Martin Mathew CLA 2014-04-08 23:43:42 EDT
Thanks Xavier for the patch.
Released the patch with the following changes:
1. Updated Copyright year and contribution details.
2. Replaced String comparison with Character comparison as the latter is efficient.
3. Removed ExpandTestAction as once this is in place double clicking on the test suite root does not activate the test file in editor but just expand the tree in the JUnit view.

Released to master with : http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=93dbc808a9cef680d165b06045426ebbae285502
Comment 16 Xavier Coulon CLA 2014-04-09 02:39:44 EDT
Thanks very much, Manju !
Comment 17 Markus Keller CLA 2014-04-09 12:22:58 EDT
We use blocks in if-statements unless it's a trivial guard in the method's top-level block. Local variables should be declared at the latest possible place. indexOf(..) tests are not more efficient than starts/endsWith, and they are hard to read. If a character like ')' follows a URL, then there must be a space in between.

TestElement#extractRawClassName(String):
testNameString.lastIndexOf(')') can return -1 or something less than index+1. We better check for this.

Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=bef8ef7c3f64c21fad26ef437d13b1c8ab93da80
Comment 18 Xavier Coulon CLA 2014-12-06 09:06:23 EST
Markus,

Sorry, I forgot to thank you for the feedback and improvements over my patch when it was merged earlier this year, but I guess it's never too late, so... thanks !
;-)