Bug 343935 - [JUnit] JUnit test case with customized Runner, can't locate the method when it contains parameters after running
Summary: [JUnit] JUnit test case with customized Runner, can't locate the method when ...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6.1   Edit
Hardware: PC All
: P3 normal with 1 vote (vote)
Target Milestone: 4.4 M7   Edit
Assignee: Andreas Schmid CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2011-04-27 04:20 EDT by Sheldon Shao CLA
Modified: 2014-04-18 06:06 EDT (History)
5 users (show)

See Also:
daniel_megert: review+


Attachments
Sceen (55.82 KB, image/png)
2011-04-27 04:34 EDT, Sheldon Shao CLA
no flags Details
A customized JUnitRunner (5.63 KB, application/octet-stream)
2011-04-27 04:36 EDT, Sheldon Shao CLA
no flags Details
Sample Test Case (331 bytes, application/octet-stream)
2011-04-27 05:07 EDT, Sheldon Shao CLA
no flags Details
Patch to solve this issue (630 bytes, patch)
2013-10-22 03:58 EDT, Andreas Schmid CLA
daniel_megert: review-
Details | Diff
Enhanced patch to fix this bug (2.42 KB, patch)
2013-11-07 06:08 EST, Andreas Schmid CLA
no flags Details | Diff
Patch to solve this issue (considering all comments) (2.42 KB, patch)
2013-11-28 04:30 EST, Andreas Schmid CLA
no flags Details | Diff
Patch to solve this issue (considering all comments) (2.68 KB, patch)
2013-11-28 04:34 EST, Andreas Schmid CLA
daniel_megert: review-
Details | Diff
other try to patch this issue without compiliing errors (3.08 KB, patch)
2014-02-15 06:42 EST, Andreas Schmid CLA
no flags Details | Diff
fixed bug 343935 (5.11 KB, application/octet-stream)
2014-03-31 12:05 EDT, Andreas Schmid CLA
no flags Details
fixed bug 343935 (4.76 KB, patch)
2014-04-16 07:54 EDT, Andreas Schmid CLA
no flags Details | Diff
Picture showing conflict (62.25 KB, image/png)
2014-04-16 09:37 EDT, Dani Megert CLA
no flags Details
fixed bug 343935 (eclipse patch) (3.79 KB, application/octet-stream)
2014-04-16 09:56 EDT, Andreas Schmid CLA
no flags Details
fixed bug 343935 (eclipse patch) (5.10 KB, patch)
2014-04-16 17:23 EDT, Andreas Schmid CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sheldon Shao CLA 2011-04-27 04:20:00 EDT
Build Identifier: M20100211-1343

Using my customized Runner extended from JUnit, when the method has some parameters. 
It can't be recognized when double clicking on the method name in JUnit View. 
A message box with "Method 'testXxxx' not found. Opening the test class." will be given. 
Then in the source code view, the EDE can't locate the right line to the method. 


Reproducible: Always

Steps to Reproduce:
1.RunWith a customized Runner, with the runner the test method may have parameters, and the parameters can be injected by the runner.
2.The case is success or failed.
3.Double clicking the case in the JUnit View.
4.A message box with "Method 'testXxxx' not found. Opening the test class." will be given.
Comment 1 Sheldon Shao CLA 2011-04-27 04:34:12 EDT
Created attachment 194130 [details]
Sceen
Comment 2 Sheldon Shao CLA 2011-04-27 04:36:43 EDT
Created attachment 194133 [details]
A customized JUnitRunner
Comment 3 Sheldon Shao CLA 2011-04-27 05:07:39 EDT
Created attachment 194136 [details]
Sample Test Case
Comment 4 Michael Rennie CLA 2011-04-27 12:11:05 EDT
Moving to JDT UI for comment.
Comment 5 Markus Keller CLA 2011-04-27 12:52:40 EDT
OpenTestAction#findElement(IJavaProject, String) could be made more resilient in case no matching method without parameters could be found.

A working patch would definitely speed things up ;-)
Comment 6 Moritz Eysholdt CLA 2012-10-03 10:55:47 EDT
see also Bug 391023
Comment 7 Andreas Schmid CLA 2013-10-22 03:58:37 EDT
Created attachment 236753 [details]
Patch to solve this issue

I have created a patch to solve this issue because we encountered the same problem using our junit-dataprovider (see https://github.com/TNG/junit-dataprovider).
Comment 8 Dani Megert CLA 2013-10-30 10:58:08 EDT
Comment on attachment 236753 [details]
Patch to solve this issue

The patch goes into the right direction but should be improved
- only look for methods that either start with "test" and have no arguments
  (if JUnit 3 test case) or are annotated with @Test (Junit 4)
- for JUnit 4 handle the case where the same method exists with different
  parameters (ask the user if more than one)
Comment 9 Andreas Schmid CLA 2013-10-30 11:11:26 EDT
OK, I see the problems. 
Is there a GIT-URL such that I can fork and send a pull request?
Comment 10 Dani Megert CLA 2013-10-30 11:53:56 EDT
(In reply to Andreas Schmid from comment #9)
> OK, I see the problems. 
> Is there a GIT-URL such that I can fork and send a pull request?

We don't pull from other repos, but you can provide a patch or upload the change via Gerrit.

You also need to sign the CLA.
Comment 11 Andreas Schmid CLA 2013-10-30 11:58:11 EDT
To provide a patch, would be easier for me, if I would know the source repository to check out. Currently I used the corresponding Eclipse feature to get it done ...
Comment 12 Dani Megert CLA 2013-10-30 12:01:39 EDT
(In reply to Andreas Schmid from comment #11)
> To provide a patch, would be easier for me, if I would know the source
> repository to check out. Currently I used the corresponding Eclipse feature
> to get it done ...

Of course. Here you go:
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/
Comment 13 Andreas Schmid CLA 2013-11-07 06:08:55 EST
Created attachment 237275 [details]
Enhanced patch to fix this bug

I have once again tried to create a patch considering comment 8 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=343935#c8).

And now I tried to consider also "only look for methods that either start with "test" and have no arguments (if JUnit 3 test case) or are annotated with @Test (Junit 4)".

But still unclear for me is the ask user part in "for JUnit 4 handle the case where the same method exists with different parameters (ask the user if more than one)". Maybe you can give me same hints or just fix that your own? My only idea is to copy the lines 117-120 (in OpenTestAction.java) and adjust them properly. But as we return null the origin part in OpenTestAction.java will be executed as well. I am not sure how you usually solve such problems even if I have some ideas ...

Maybe you can give me same hints and/or examples to the last point clear for me.

I would enjoy to help :)
Comment 14 Dani Megert CLA 2013-11-07 07:41:40 EST
(In reply to Andreas Schmid from comment #13)
> Created attachment 237275 [details] [diff]
> Enhanced patch to fix this bug
> 
> I have once again tried to create a patch considering comment 8
> (https://bugs.eclipse.org/bugs/show_bug.cgi?id=343935#c8).
> 
> And now I tried to consider also "only look for methods that either start
> with "test" and have no arguments (if JUnit 3 test case) or are annotated
> with @Test (Junit 4)".
> 
> But still unclear for me is the ask user part in "for JUnit 4 handle the
> case where the same method exists with different parameters (ask the user if
> more than one)". 

What I meant, is to present the list of ambiguous methods to the user, so that he can choose one.
Comment 15 Andreas Schmid CLA 2013-11-07 07:57:53 EST
(In reply to Dani Megert from comment #14)
> (In reply to Andreas Schmid from comment #13)
> > Created attachment 237275 [details] [diff]
> > Enhanced patch to fix this bug
> > 
> > I have once again tried to create a patch considering comment 8
> > (https://bugs.eclipse.org/bugs/show_bug.cgi?id=343935#c8).
> > 
> > And now I tried to consider also "only look for methods that either start
> > with "test" and have no arguments (if JUnit 3 test case) or are annotated
> > with @Test (Junit 4)".
> > 
> > But still unclear for me is the ask user part in "for JUnit 4 handle the
> > case where the same method exists with different parameters (ask the user if
> > more than one)". 
> 
> What I meant, is to present the list of ambiguous methods to the user, so
> that he can choose one.

Do you have a code example for me? Or can you fix it?
Comment 16 Dani Megert CLA 2013-11-11 06:43:11 EST
(In reply to Andreas Schmid from comment #15)
> > What I meant, is to present the list of ambiguous methods to the user, so
> > that he can choose one.
> 
> Do you have a code example for me? Or can you fix it?

See SelectionConverter.selectJavaElement(IJavaElement[], Shell, String, String)
Comment 17 Andreas Schmid CLA 2013-11-28 04:30:37 EST
Created attachment 237784 [details]
Patch to solve this issue (considering all comments)

Next try for a patch to this issue, this time with an dedicated chooser dialog if multiple Methods exists.
Comment 18 Andreas Schmid CLA 2013-11-28 04:34:04 EST
Created attachment 237785 [details]
Patch to solve this issue (considering all comments)

Sorry attached wrong file in comment #17.

Next try for a patch to this issue, this time with an dedicated chooser dialog if multiple Methods exists.
Comment 19 Andreas Schmid CLA 2014-02-09 07:52:37 EST
Thanks again, for merging this issue. Is there already a release date for a new version of eclipse-junit containing this fix?
Comment 20 Dani Megert CLA 2014-02-14 05:16:26 EST
Comment on attachment 237785 [details]
Patch to solve this issue (considering all comments)

I get compile errors when I apply this patch.
Comment 21 Andreas Schmid CLA 2014-02-14 06:37:47 EST
Which repo and commit do you use?
Comment 22 Dani Megert CLA 2014-02-14 06:41:40 EST
(In reply to Andreas Schmid from comment #21)
> Which repo and commit do you use?

http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/tree/org.eclipse.jdt.junit

master branch
Comment 23 Andreas Schmid CLA 2014-02-14 06:52:50 EST
I checked out http://git.eclipse.org/gitroot/jdt/eclipse.jdt.ui.git and applied the patch. Unfortunately, I cannot build it using "mvn package" (due to "Unable to satisfy dependency from org.eclipse.ltk.core.refactoring 3.6.100.qualifier to bundle org.eclipse.text [3.5.0,4.0.0).; No solution found because the problem is unsatisfiable.]") but in Eclipse it is working!

I am sorry to cannot help you further ... Can you nevertheless fix it?
Comment 24 Dani Megert CLA 2014-02-14 07:03:39 EST
(In reply to Andreas Schmid from comment #23)
> I checked out http://git.eclipse.org/gitroot/jdt/eclipse.jdt.ui.git and
> applied the patch. Unfortunately, I cannot build it using "mvn package" (due
> to "Unable to satisfy dependency from org.eclipse.ltk.core.refactoring
> 3.6.100.qualifier to bundle org.eclipse.text [3.5.0,4.0.0).; No solution
> found because the problem is unsatisfiable.]") but in Eclipse it is working!
> 
> I am sorry to cannot help you further ... Can you nevertheless fix it?

If you look at your patch, you'll see that you use classes which aren't imported. This is doomed to fail.

No, I don't have time to work on this, sorry.
Comment 25 Andreas Schmid CLA 2014-02-15 06:42:39 EST
Created attachment 239978 [details]
other try to patch this issue without compiliing errors

(In reply to Dani Megert from comment #24)
> If you look at your patch, you'll see that you use classes which aren't
> imported. This is doomed to fail.
> 
> No, I don't have time to work on this, sorry.

I'm sorry for that, but as I cannot compile using "mvn package" due to "Unable to satisfy dependency from [...]" I am just able to import the plugin within Eclipse and try to apply the changes to source code from git manually.

Here's another try!

P.S.: Which repository do I have to add to my settings.xml or can you provide me yours, that I am able to compile it using "mvn compile"?
Comment 26 Dani Megert CLA 2014-02-20 02:08:21 EST
(In reply to Andreas Schmid from comment #25)
> Here's another try!

Thanks. This patch now compiles! Using internal SelectionConverter is a corner case and OK in this case, but you should never reuse internal messages from another bundle. They should be copied into JUnitMessages.

Please also sign the CLA. Without that we can't take your patch.

 
> P.S.: Which repository do I have to add to my settings.xml or can you
> provide me yours, that I am able to compile it using "mvn compile"?

You should use the Eclipse IDE + EGit and not mvn or other tools, unless of course *you* know how to compile there ;-). In Eclipse with EGit support you can simply clone the git://git.eclipse.org/gitroot/jdt/eclipse.jdt.ui.git repository and import the JUnit project from that cloned repository.
Comment 27 Andreas Schmid CLA 2014-03-31 12:05:05 EDT
Created attachment 241439 [details]
fixed bug 343935

(In reply to Dani Megert from comment #26)
> 
> Thanks. This patch now compiles! Using internal SelectionConverter is a
> corner case and OK in this case, but you should never reuse internal
> messages from another bundle. They should be copied into JUnitMessages.
done, see new patch.

> 
> Please also sign the CLA. Without that we can't take your patch.
done, see https://projects.eclipse.org/users/andreas-schmid/cla

> 
> You should use the Eclipse IDE + EGit and not mvn or other tools, unless of
> course *you* know how to compile there ;-). In Eclipse with EGit support you
> can simply clone the git://git.eclipse.org/gitroot/jdt/eclipse.jdt.ui.git
> repository and import the JUnit project from that cloned repository.
Thanks, I have tried that and clone as well as import works properly. Unfortunately, the imported projects from master branch shows round about 3000 problems in Eclipse problem view ...
Comment 28 Dani Megert CLA 2014-04-16 06:05:28 EDT
(In reply to Dani Megert from comment #26)
> (In reply to Andreas Schmid from comment #25)
> > Here's another try!
> 
> but you should never reuse internal
> messages from another bundle. They should be copied into JUnitMessages.

This is still the case in the latest patch.
Comment 29 Andreas Schmid CLA 2014-04-16 06:38:37 EDT
But I have added and reference following two new entries in ActionMessages.java (copied from attachment "fixed bug 343935"): 

+	public static String OpenTestAction_description;
+	public static String OpenTestAction_select_element;
Comment 30 Dani Megert CLA 2014-04-16 07:09:05 EDT
(In reply to Andreas Schmid from comment #29)
> But I have added and reference following two new entries in
> ActionMessages.java (copied from attachment "fixed bug 343935"): 
> 
> +	public static String OpenTestAction_description;
> +	public static String OpenTestAction_select_element;

But in the wrong plug-in. Messages should never be accessed from another bundle.

Hence also this is not correct:
+import org.eclipse.debug.internal.ui.actions.ActionMessages;
Comment 31 Andreas Schmid CLA 2014-04-16 07:54:13 EDT
Created attachment 242044 [details]
fixed bug 343935

(In reply to Dani Megert from comment #30)
> But in the wrong plug-in. Messages should never be accessed from another
> bundle.
> 
> Hence also this is not correct:
> +import org.eclipse.debug.internal.ui.actions.ActionMessages;

I am sorry. I just feel to be too stupid to get it right. Maybe this time?

P.S. Thanks for being that patient with me ;-)
Comment 32 Dani Megert CLA 2014-04-16 09:37:49 EDT
Created attachment 242051 [details]
Picture showing conflict

This patch does not apply on 'master'.
Comment 33 Andreas Schmid CLA 2014-04-16 09:56:45 EDT
Created attachment 242054 [details]
fixed bug 343935 (eclipse patch)

(In reply to Dani Megert from comment #32)
> Created attachment 242051 [details]
> Picture showing conflict
> 
> This patch does not apply on 'master'.

arg ... you want to apply it using Eclipse ... please use the new attachment. 

(With "git apply $FILE" it should have worked either ...)
Comment 34 Dani Megert CLA 2014-04-16 12:06:40 EDT
The patch looks good. Just some minor tweaks:

> OpenTestAction_description
This should be OpenTestAction_title with value "Go to Test"

When I hit cancel on the dialog, I get another dialog. That's not OK. It should just do nothing in that case.

Please also add your credentials to the copyright notices, e.g.
Terry Parker <tparker@google.com> - Protect against poorly behaved completion proposers - http://bugs.eclipse.org/429925

You need to confirm that you want to contribute this by saying:

"This contribution complies with http://www.eclipse.org/legal/CoO.php"

Thanks.
Comment 35 Andreas Schmid CLA 2014-04-16 17:23:28 EDT
Created attachment 242074 [details]
fixed bug 343935 (eclipse patch)

Hi Dani,

(In reply to Dani Megert from comment #34)
> The patch looks good. Just some minor tweaks:
thanks so far for your effort ...

> 
> > OpenTestAction_description
> This should be OpenTestAction_title with value "Go to Test"
done.

> 
> When I hit cancel on the dialog, I get another dialog. That's not OK. It
> should just do nothing in that case.
Ah ok, I see, this is really a design flaw. I know returned the list of found element (never null) and handled this list in the calling method properly. I like this even better because the showing of dialogs is handling within the same method. Now I open the "type" if the user clicks "Cancel" (same as with error if no method is found). Unfortunately, I cannot do anything because returning a "null" leads to a "MessageDialog.openError(getShell(), ...);" in the calling method "org.eclipse.jdt.internal.junit.ui.OpenEditorAction.run()"
What do you think?

> 
> Please also add your credentials to the copyright notices, e.g.
> Terry Parker <tparker@google.com> - Protect against poorly behaved
> completion proposers - http://bugs.eclipse.org/429925
done.

> 
> You need to confirm that you want to contribute this by saying:
> 
> "This contribution complies with http://www.eclipse.org/legal/CoO.php"
I confirm, that this contribution complies with http://www.eclipse.org/legal/CoO.php.

> 
> Thanks.
Attached is the new patch (unfortunately I couldn't directly pushed it to gerrit (ref/for/master) :-( (as I say, Terry did that on the linked issue)
Comment 36 Dani Megert CLA 2014-04-18 04:44:29 EDT
I agree fixing the second dialog issue is a but strange. Instead of polluting the code for that corner case I think we live with it.

I've combined your last two patches into one, fixed the NLS warnings and committed as
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=f6db2c136a709858311cfe3a3a7938e8947b9e57

Thanks Andreas!


> Attached is the new patch (unfortunately I couldn't directly pushed it to 
> gerrit (ref/for/master) :-( (as I say, Terry did that on the linked issue)

You need to configure your repository for Gerrit. For details see https://wiki.eclipse.org/JDT_UI/How_to_Contribute#Provide_a_contribution_using_Gerrit
Comment 37 Andreas Schmid CLA 2014-04-18 06:06:16 EDT
(In reply to Dani Megert from comment #36)
> I agree fixing the second dialog issue is a but strange. Instead of
> polluting the code for that corner case I think we live with it.
> 
> I've combined your last two patches into one, fixed the NLS warnings and
> committed as
> http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/
> ?id=f6db2c136a709858311cfe3a3a7938e8947b9e57
great!

> 
> Thanks Andreas!
No, thank you for your help!

> 
> 
> > Attached is the new patch (unfortunately I couldn't directly pushed it to 
> > gerrit (ref/for/master) :-( (as I say, Terry did that on the linked issue)
> 
> You need to configure your repository for Gerrit. For details see
> https://wiki.eclipse.org/JDT_UI/
> How_to_Contribute#Provide_a_contribution_using_Gerrit
Will do it for the next bug :)