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

Bug 172256

Summary: [JUnit] Test tree status is rendered incorrectly in JUnit View when the same test is included multiple times (JUnit4 Runner)
Product: [Eclipse Project] JDT Reporter: Dan Yocum <dagitar>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: RESOLVED NOT_ECLIPSE QA Contact:
Severity: normal    
Priority: P5 CC: caspar_d, daniel_megert, david, john.dean.3, kane.mx, kane.zhu, marc.khouzam, martin.fluegge, steffen.pingel, stepper, sutter, urazov
Version: 3.2.1Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Dan Yocum CLA 2007-01-30 20:50:12 EST
Build ID: M20060921-0945

Steps To Reproduce:
1.create a test, and a suite that includes that test in the same package:

package eclipse.bug;

import static org.junit.Assert.*;

import org.junit.Test;

public class TheTest {

	public int div(int i, int j) { 
		return i / j; 
	}
	
	@Test public void divNumZero () {
		assert 0 == div(0, 5);
	}
	
	@Test (expected=IllegalArgumentException.class) public void divDemZero () {
		div(5, 0);
	}
	
}
package eclipse.bug;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(value=Suite.class)
@SuiteClasses(value={TheTest.class})
public class TheSuite {
}

2. select the package to run as JUnit tests.
3. check the junit view, the status for test cases is updated only for "TheTest" node, but not for "TheSuite" node.

(The number of runs, errors and failures are correct though) 


More information:
Comment 1 Markus Keller CLA 2007-05-31 08:49:16 EDT
This is a problem with JUnit 4. In JUnit 3, tests were identified by individual Test objects. JUnit 4 identifies tests with Description objects, which are just containers for a declaring type and a test method. This makes the same test indistinguishable in different branches of the tree, since Descriptions don't know their parent, and they are are often recreated.

I'll see what we can do for 3.4, but I think this depends on fixes in org.junit.
Comment 2 Marc Khouzam CLA 2009-05-07 14:56:34 EDT
I ran into this problem when running a Suite of Suites.
What I want to do is to have every suite run the same set of tests, but the suite itself starts off by setting a value somewhere; each test reads that value and behaves different based on it.

The problem is that each test, although behaving differently is the same class and therefore named the same by the Description class.  So, in the JUnit view, all updates to the test are done on the last occurrence of that test.

I guess, I'm gonna have to write dummy test classes, inheriting from the real test classes so I can give them a different name.
Comment 3 Andrey Urazov CLA 2009-12-16 06:22:04 EST
We have exactly the same problem. A test suite that is a hierarchy of test cases created dynamically. In various parts of the hierarchy there may be test cases with the same name and all the test cases are actually instances of the same class but instantiated with different data.

When we run the test suite in Eclipse using Junit4 runner, the results are not properly shown in the UI.

We have recently migrated to Junit4 from Junit 3.7 and suddenly started to suffer from this mysterious bug.

What are the plans regarding fixing this?

Many thanks,

Andrey
Comment 4 Markus Keller CLA 2009-12-16 07:14:19 EST
I had another quick look, and the problem is really in JUnit 4: org.junit.runner.notification.RunListener only reports org.junit.runner.Description objects, and there's no way to find the right parent for a description since descriptions are often recreated and don't have a parent link.

In JUnit 3, junit.framework.TestListener reported separate Test objects which could be distinguished because they are not identical.

This can only be solved if JUnit fixes this problem. If you want to help fixing this, please file a bug against JUnit (and post links so that this bug knows about the other and vice versa).
Comment 5 Markus Keller CLA 2009-12-16 07:18:48 EST
> [..] all the test cases are actually instances of the
> same class but instantiated with different data.

This could maybe work if you used org.junit.runners.Parameterized. But it would also need hacks in Eclipse, since org.junit.runner.Description#equals(Object) is broken (does not compare annotations).
Comment 6 Markus Keller CLA 2010-03-08 06:14:23 EST
We can't do anything here without support from JUnit.
Comment 7 Markus Keller CLA 2010-03-08 06:18:46 EST
*** Bug 303452 has been marked as a duplicate of this bug. ***
Comment 8 Markus Keller CLA 2010-03-08 06:37:01 EST
*** Bug 303182 has been marked as a duplicate of this bug. ***
Comment 9 Markus Keller CLA 2010-05-27 10:53:44 EDT
*** Bug 314596 has been marked as a duplicate of this bug. ***
Comment 10 Markus Keller CLA 2010-06-18 12:11:23 EDT
*** Bug 317313 has been marked as a duplicate of this bug. ***
Comment 11 Markus Keller CLA 2010-09-03 08:06:58 EDT
*** Bug 324376 has been marked as a duplicate of this bug. ***
Comment 12 Markus Keller CLA 2010-11-19 12:08:20 EST
Corresponding JUnit bug:
https://github.com/KentBeck/junit/issues/issue/139
Comment 13 michael sutter CLA 2017-02-23 12:02:51 EST
I have a short question on this. I can see the same issue when we execute our tests with a feature toggle variation. 
Anyway in case I execute the tests via Maven from the command line and open the created junit result file I'm able to see the results of (in our case) both runs.

Is the behavior different in such a case?