Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ParameterizedTest is not recognized by the method selector using Junit Platform Console Standalone #3748

Closed
rcasia opened this issue Mar 31, 2024 · 3 comments

Comments

@rcasia
Copy link

rcasia commented Mar 31, 2024

Junit Standalone cannot discover a test method that has @ParameterizedTest annotation when runned using the method selector. When I run other test methods it works as usual. Also it discovers the parameterized tests when using the class selector.

Steps to reproduce

  1. Wrote this test:
  @ParameterizedTest
  @CsvSource({ "1", "2", "3" })
  void testNumbers(int i) {
    assertEquals(i, 3);
  }
  1. Run this command
./mvnw -q dependency:build-classpath -Dmdep.outputFile=/tmp/classpath.txt

javac -d /tmp/outputDir -cp $(cat /tmp/classpath.txt) src/main/**/*.java

javac -d /tmp/outputDir -cp $(cat /tmp/classpath.txt):/tmp/outputDir src/test/**/*.java

java -jar ~/junit-platform-console-standalone-1.10.2.jar execute -cp $(cat /tmp/classpath.txt):/tmp/outputDir -m=com.rcasia.demo.DemoApplicationTests#testNumbers --fail-if-no-tests --reports-dir=/tmp/reportDir

Expected

To discover the parameterized test method.

Actual

Does not discover the parameterized test method.

Logs 🗒️

org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:160)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverSafely(EngineDiscoveryOrchestrator.java:132)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:107)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:78)
at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:99)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:85)
at org.junit.platform.launcher.core.DelegatingLauncher.execute(DelegatingLauncher.java:47)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:63)
at org.junit.platform.console.tasks.ConsoleTestExecutor.executeTests(ConsoleTestExecutor.java:102)
at org.junit.platform.console.tasks.ConsoleTestExecutor.lambda$execute$1(ConsoleTestExecutor.java:71)
at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.replaceThreadContextClassLoaderAndInvoke(CustomContextClassLoaderExecutor.java:42)
at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.invoke(CustomContextClassLoaderExecutor.java:33)
at org.junit.platform.console.tasks.ConsoleTestExecutor.execute(ConsoleTestExecutor.java:71)
at org.junit.platform.console.options.ExecuteTestsCommand.execute(ExecuteTestsCommand.java:61)
at org.junit.platform.console.options.ExecuteTestsCommand.execute(ExecuteTestsCommand.java:27)
at org.junit.platform.console.options.BaseCommand.call(BaseCommand.java:74)
at org.junit.platform.console.shadow.picocli.CommandLine.executeUserObject(CommandLine.java:2041)
at org.junit.platform.console.shadow.picocli.CommandLine.access$1500(CommandLine.java:148)
at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
at org.junit.platform.console.shadow.picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
at org.junit.platform.console.shadow.picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
at org.junit.platform.console.shadow.picocli.CommandLine.execute(CommandLine.java:2170)
at org.junit.platform.console.options.MainCommand.runCommand(MainCommand.java:137)
at org.junit.platform.console.options.MainCommand.run(MainCommand.java:125)
at org.junit.platform.console.options.CommandFacade.run(CommandFacade.java:36)
at org.junit.platform.console.ConsoleLauncher.run(ConsoleLauncher.java:57)
at org.junit.platform.console.ConsoleLauncher.run(ConsoleLauncher.java:42)
at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:35)
Caused by: org.junit.platform.commons.JUnitException: MethodSelector [className = 'rcm.mailtracker.MailtrackerApplicationTests', methodName = 'numbers', parameterTypes = '', classLoader = null] resolution failed
at org.junit.platform.launcher.listeners.discovery.AbortOnFailureLauncherDiscoveryListener.selectorProcessed(AbortOnFailureLauncherDiscoveryListener.java:39)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:103)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.run(EngineDiscoveryRequestResolution.java:83)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver.resolve(EngineDiscoveryRequestResolver.java:113)
at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:46)
at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:69)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152)
... 29 more
Caused by: org.junit.platform.commons.PreconditionViolationException: Could not find method with name [numbers] in class [rcm.mailtracker.MailtrackerApplicationTests].
at org.junit.platform.engine.discovery.MethodSelector.lambda$lazyLoadJavaMethod$2(MethodSelector.java:258)
at java.base/java.util.Optional.orElseThrow(Optional.java:403)
at org.junit.platform.engine.discovery.MethodSelector.lazyLoadJavaMethod(MethodSelector.java:256)
at org.junit.platform.engine.discovery.MethodSelector.getJavaMethod(MethodSelector.java:207)
at org.junit.jupiter.engine.discovery.MethodSelectorResolver.resolve(MethodSelectorResolver.java:90)
at org.junit.jupiter.engine.discovery.MethodSelectorResolver.resolve(MethodSelectorResolver.java:75)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.lambda$resolve$2(EngineDiscoveryRequestResolution.java:150)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1602)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:189)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:126)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:92)
... 34 more

Here there is a repo to try it out: https://github.com/rcasia/issue-junit5-parameterized-test

Context

  • Used versions (Jupiter/Vintage/Platform): Jupiter
  • Build Tool/IDE: Standalone (junit-platform-console-standalone-1.10.2)
@mpkorstanje
Copy link
Contributor

mpkorstanje commented Apr 1, 2024

Without trying to reproduce your problem it looks like you are missing the parameter type list in your method selector.

* <p>The following formats are supported.
*
* <ul>
* <li>{@code [fully qualified class name]#[methodName]}</li>
* <li>{@code [fully qualified class name]#[methodName](parameter type list)}
* </ul>

I suppose the documentation could be read as suggesting that the first format matches regardless of parameters rather than being a short hand for methods without parameters.

@rcasia
Copy link
Author

rcasia commented Apr 1, 2024

Thanks. Problem solved 👍 I sumbitted a PR to add that extra clarification on the User Guide.

@sbrannen
Copy link
Member

sbrannen commented Apr 5, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants