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

TestLauncher does not discover tests in Junit5 @Nested class #29603

Closed
jdneo opened this issue Jun 19, 2024 · 5 comments
Closed

TestLauncher does not discover tests in Junit5 @Nested class #29603

jdneo opened this issue Jun 19, 2024 · 5 comments
Assignees
Labels
a:bug closed:question usage question or request for help in:tooling-api

Comments

@jdneo
Copy link

jdneo commented Jun 19, 2024

Current Behavior

When using TestLauncher to run tests with @Nested annotation class, Gradle failed to run them.

Expected Behavior

TestLauncher should run tests for @Nested annotation class.

Context (optional)

No response

Steps to Reproduce

Sample project to reproduce the issue: https://github.com/jdneo/gradle-test-launcher

Gradle version

8.4

Build scan URL (optional)

No response

Your Environment (optional)

No response

@ov7a
Copy link
Member

ov7a commented Jun 20, 2024

The issue is in the backlog of the relevant team and is prioritized by them.

@ov7a ov7a removed the to-triage label Jun 20, 2024
@donat donat added to-triage and removed to-triage labels Jun 24, 2024
@donat donat self-assigned this Jun 25, 2024
@donat
Copy link
Member

donat commented Jun 25, 2024

This is a corner-case of how test filters are handled on the command-line and it is an expected behaviour.

When parsing a command-line test patterns, Gradle expects a test filter with the following format: [className][.[methodName]]?
If the method name is missing then a .* pattern is appended to the final test filter pattern. TestLauncher is less permissive as it provides explicit API for selecting test tasks and test methods.

In the reproducer, you can run select the test with its fully-qualified name

.withJvmTestClasses("com.example.project.NestedTests$NestedClassB$ADeeperClass")

Or you can work around the issue by using the same wildcard approach that is used by the command-line:

.withJvmTestClasses("com.example.project.NestedTests.*")

@donat donat closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2024
@jdneo
Copy link
Author

jdneo commented Jun 26, 2024

Hi @donat,

Confirmed that using com.example.project.NestedTests$NestedClassB$ADeeperClass can make it work. But it still not works when appending .*, the error says:

Caused by: org.gradle.api.tasks.testing.TestExecutionException: No matching tests found in any candidate test task.
    Requested tests:
        Test class com.example.project.NestedTests.*

@donat
Copy link
Member

donat commented Jun 26, 2024

There's a typo in my previous message. The extra suffix should be * (instead of .*):

.withJvmTestClasses("com.example.project.NestedTests*") 

@ov7a ov7a added closed:question usage question or request for help and removed to-triage labels Jun 26, 2024
@jdneo
Copy link
Author

jdneo commented Jun 26, 2024

It works, thank you @donat.

Maybe consider to add this trick to the javadoc of withJvmTestClasses?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug closed:question usage question or request for help in:tooling-api
Projects
None yet
Development

No branches or pull requests

3 participants