Community
Participate
Working Groups
In CodeMining/CodeLens context, we need to know if a given IMethod is a JUnit test method or not to drawn codemining/codelens. Today vscode-java-test (JUnit CodeLens inside VSCode) and jdt-codemining (JUnit CodeMining inside Eclipse IDE) checks if it exists an @test annotation before the method: * for vscode-java-test (see isTestMethod): https://github.com/Microsoft/vscode-java-test/search?utf8=%E2%9C%93&q=isTestMethod&type= * for jdt-codemining (see isTestMethod): https://github.com/angelozerr/jdt-codemining/blob/master/org.eclipse.jdt.codemining/src/org/eclipse/jdt/junit/codemining/JUnitCodeMiningProvider.java#L130 It seems that it with JUnit4 but not with JUnit5 (@Sarika, could add a sample with JUnit5 which doesn't work please). To fix this problem, it should be cool if we could have an helper like isTestMethod(IMethod). An idea is to add a new method isTestMethod(IMethod method) in the existing interface org.eclipse.jdt.internal.junit.launcher.ITestFinder: ------------------------------------------------------ public interface ITestFinder { ... boolean isTestMethod(IMethod method) throws CoreException; } ------------------------------------------------------ Each JUnit version (JUnit3TestFinder, JUnit4TestFinder, JUnit5TestFinder) will implement their logic to know if a given method is a JUnit test method by implementing isTestMethod(IMethod method). After we could do that: ------------------------------------------------------ IMethod method = ... ITestKind testKind= TestKindRegistry.getContainerTestKind(method.getParent()); boolean isTestMethod = testKind.getFinder().isTestMethod(method); ------------------------------------------------------
JDT Core is totally unaware of JUnit so this can be provided by JDT UI (if possible).
It is the responsibility of JUnit 5 framework to discover all the test methods and hence it is not required in JDT. If you need this for code minings then you can refer the implementations of ITestFinder.isTest(IType type) which check for a test method also internally. Example: JUnit5TestFinder.Annotation.annotatesAtLeastOneMethod(ITypeBinding type).
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.
Reopen the bug if you are planning to work on it.