Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 286343

Summary: [JUnit] JUnit3TestFinder does doesn't quite behave correctly
Product: [Eclipse Project] JDT Reporter: Robert Konigsberg <konigsberg>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P5 CC: darin.eclipse, markus.kell.r
Version: 3.4.1Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: stalebug
Attachments:
Description Flags
Test case that describes the conditions of this bug none

Description Robert Konigsberg CLA 2009-08-11 17:45:25 EDT
Build ID: M20080911-1700

Steps To Reproduce:
Let's discuss two cases where JUnit3TestFinder is doing the wrong thing. Note that these probably also apply to the JUnit4TestFinder.

1.

import junit.framework.TestSuite;

class X extends Object {
  public TestSuite suite() {
     ...
  }
}

The method JU3TF.isTest will fail here, because the method suite() does not return an object of type "Test", but of "TestSuite". Since TestSuite extends Test, this ought to be an acceptable subtype.

Here's another case


class Test extends Object {
  ...
}

class X extends Object {
  public Test suite() {
     ...
  }
}

In this case JU3TF will consider this type to be a valid test, even though it doesn't actually implement junit.framework.Test.

The reason both of these cases do the wrong thing is because of this line in TestSearchEngine.hasSuiteMethod:

if (!Signature.getSimpleName(Signature.toString(method.getReturnType())).equals(JUnitPlugin.SIMPLE_TEST_INTERFACE_NAME)) {

which basically says: if the return type of the "suite" method is resolved to the string "Test", it's good.

Now, as for what _I_ need: I do need the test finder to accept suite methods that return instances of junit.framework.TestSuite. Would that be possible?

Note that my build id is 3.4.1. I'd love to recreate this in 3.5, but I'm having a little trouble right now.

Thoughts? Advice?

More information:
Comment 1 Robert Konigsberg CLA 2009-08-11 17:54:08 EDT
I am reprioritizing this as major because we have over 1,200 cases where the suite method returns TestSuite, and so can't be launched.
Comment 2 Markus Keller CLA 2009-08-26 13:55:56 EDT
I would always be good to have a self-contained test case that shows the problem. E.g. the examples in comment 0 have never been tested (the suite() method must be static).

A fix would also have to touch TestSearchEngine.findSuiteMethods(..) to make sure we find the same tests as with TestSearchEngine.hasSuiteMethod(..).

However, we have to be careful:
- should not introduce a big performance hit (e.g. by creating many type hierarchies)
- should not introduce false positives (e.g. suite() methods whose return type is not instanceof Test)
Comment 3 Markus Keller CLA 2009-08-28 04:57:15 EDT
JUnit's specification for this feature is again very sparse, and this hasn't been a problem for years up to now, so I wouldn't classify this as major.
Comment 4 Robert Konigsberg CLA 2009-08-31 14:53:01 EDT
Created attachment 146098 [details]
Test case that describes the conditions of this bug

My test case is 1.4 compatible, but the test expects a 1.5 VM to run. I'm fairly confident that's the only adjustment required, but you know better than I.
Comment 5 Robert Konigsberg CLA 2009-08-31 14:59:01 EDT
Hi Markus,

So good. I've created the test case. Hopefully that will be significantly helpful.

You are concerned about performance. You know about this better than I. What kind of costs are unacceptable? Let's say for discussion sake I wrote a patch. Specific guidance is key here -- soft terms like "Not too slow" may be a bit of a problem. If you have some good performance tests, I would appreciate being pointed to them.

You are concerned about false positives -- did you see that my original bug included a current false positive? :)
Comment 6 Robert Konigsberg CLA 2010-03-08 12:17:25 EST
This just came up again, so, ping! Any chance this could make it in to 3.6?
Comment 7 Eclipse Genie CLA 2020-05-01 20:29:49 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.