Bug 564914 - [Junit5] test not found
Summary: [Junit5] test not found
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.17   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted, investigate
Depends on:
Blocks:
 
Reported: 2020-07-03 12:53 EDT by Carsten Hammer CLA
Modified: 2023-01-17 12:46 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carsten Hammer CLA 2020-07-03 12:53:23 EDT
see sample code in jdt.ui itself. Eclipse does not find the test class because of the migration from junit 4 to junit 5.
https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/165807
Look at org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/CallHierarchyTest.java
Comment 1 Eclipse Genie CLA 2020-07-03 13:08:05 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/165811
Comment 2 Carsten Hammer CLA 2020-07-03 17:16:53 EDT
CallHierarchyTest.java can be executed. You have to make sure that you use a junit 5 run configuration. Under some circumstances eclipse generates a junit 4 run configuration if you run the test that does not work.
For the linked gerrit it is still not clear why the test testTestAnnotationJunit5() fails. 

Besides it is strange that since I changed it to use

JavaProjectHelper.set18CompilerOptions(fProject);

instead of 

JavaProjectHelper.set15CompilerOptions(fProject);

I have to use

assertEquals(TestKindRegistry.JUNIT5_TEST_KIND_ID, testKind.getId());

instead of

assertEquals(TestKindRegistry.JUNIT4_TEST_KIND_ID, testKind.getId());

I am not sure what these two things have to do with each other. Is this expected?
Comment 3 Carsten Hammer CLA 2020-07-03 17:49:39 EDT
When I change the code in JunitCore.java like this the test is found:

	public static IType[] findTestTypes(IJavaElement container, IProgressMonitor monitor) throws CoreException, OperationCanceledException {
		final Set<IType> result= new HashSet<>();
//		JUnit4TestFinder finder= new JUnit4TestFinder();
		JUnit5TestFinder finder= new JUnit5TestFinder();
		finder.findTestsInContainer(container, result, monitor);

		return result.toArray(new IType[result.size()]);
	}
Comment 4 Noopur Gupta CLA 2020-08-14 10:28:37 EDT
(In reply to Carsten Hammer from comment #3)
> When I change the code in JunitCore.java like this the test is found:
> 
> 	public static IType[] findTestTypes(IJavaElement container,
> IProgressMonitor monitor) throws CoreException, OperationCanceledException {
> 		final Set<IType> result= new HashSet<>();
> //		JUnit4TestFinder finder= new JUnit4TestFinder();
> 		JUnit5TestFinder finder= new JUnit5TestFinder();
> 		finder.findTestsInContainer(container, result, monitor);
> 
> 		return result.toArray(new IType[result.size()]);
> 	}

Looking into the details and history of this method, it was added in bug 243294.

The current method is used in JDT for JUnit4TestFinderTest. 

Please check if you need something similar for your scenario as well.
Comment 5 Noopur Gupta CLA 2021-01-04 02:31:19 EST
Carsten, please provide a scenario to reproduce the current problem here with details. Also, explain the proposed solution as adding a reference to JUnit 5 in JUnit4TestFinder does not look correct.
Comment 6 Carsten Hammer CLA 2021-01-04 11:41:41 EST
(In reply to Noopur Gupta from comment #5)
> Carsten, please provide a scenario to reproduce the current problem here
> with details. Also, explain the proposed solution as adding a reference to
> JUnit 5 in JUnit4TestFinder does not look correct.

You must be right of course...

Is it possible that someone takes the time to explain why the new tests part of the gerrit fail without the changes? And I still have no explanation for the strange behavior from comment2. Maybe this gives me some insights..

I derived the tests from the existing junit 4 tests after I experienced problems to execute and still do not get the idea why it is wrong. I saw others having issues with junit 5 too. Unfortunately it is not clear how to reproduce.

I can see highly suspicious code like what is mentioned in

https://bugs.eclipse.org/bugs/show_bug.cgi?id=570024

and

https://bugs.eclipse.org/bugs/show_bug.cgi?id=569848
Comment 7 Noopur Gupta CLA 2021-01-05 03:46:45 EST
I will also add the "helpwanted" keyword along with "investigate" so that anyone interested can take a look.
Comment 8 Eclipse Genie CLA 2023-01-17 12:46:17 EST
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.

If you have further information on the current state of the bug, please add it. 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.