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

Feature suggestion: Detect missing @Nested annotations #1736

Open
ivoanjo opened this issue Jan 17, 2019 · 8 comments
Open

Feature suggestion: Detect missing @Nested annotations #1736

ivoanjo opened this issue Jan 17, 2019 · 8 comments

Comments

@ivoanjo
Copy link

ivoanjo commented Jan 17, 2019

Hello there, and thanks for JUnit! 👋

My team has recently migrated to JUnit 5, and previously we were previously using the junit-hierarchicalcontextrunner for nested tests.
One big difference from that one is that on JUnit 5 the native nested tests require that nested classes be annotated with the @Nested annotation.

We've now been using it for a few weeks, and my team found that sometimes we forget to add an @Nested annotation to an inner class.

This leads to a test suite that is apparently green, but that in reality is missing tests, and is hard to spot.

Would it be possible to either:

  • add a validation that would warn us that we could possibly be missing @Nested -- by for instance detecting that a nested class had JUnit annotations on it but would not be executed

  • have a mode/option/top-level annotation for executing tests in nested classes without needing an explicit @Nested

Thanks! 🙏

Related issues

@marcphilipp
Copy link
Member

marcphilipp commented Jan 17, 2019

@ivoanjo Thanks for providing such a detailed use case description. That's very helpful! This is definitely something that JUnit should validate at some point. For the time being, I think you could implement the validation yourself by implementing a custom extension and registering it globally.

Would you be interested in giving that a try?

@sbrannen
Copy link
Member

For the time being, I think you could implement the validation yourself by implementing a custom extension and registering it globally.

That would unfortunately only work when such an extension is invoked for an enclosing test class that has testable methods. Otherwise, if the enclosing class is not registered as a test class itself, a custom extension would never be invoked.

The issue here is that the validation we have in place is executed during the discovery phase, and if the validation (i.e., our IsNestedTestClass predicate) fails... both the enclosing class and the intended-to-be @Nested test class get silently ignored with no TestDescriptor in the execution tree.

@ivoanjo
Copy link
Author

ivoanjo commented Jan 19, 2019

Thanks @marcphilipp and @sbrannen for the feedback.

Would you be interested in giving that a try?

I don't have enough bandwidth to pick this up on my free time in the next few months, sorry! Hopefully some brave soul can help out in the meanwhile 🙂

@stale
Copy link

stale bot commented May 13, 2021

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the status: stale label May 13, 2021
@ivoanjo
Copy link
Author

ivoanjo commented May 13, 2021

Would still be nice to have this!

@stale stale bot removed the status: stale label May 13, 2021
@marcphilipp marcphilipp removed this from the 5.x Backlog milestone Jun 19, 2021
@stale
Copy link

stale bot commented Jun 21, 2022

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the status: stale label Jun 21, 2022
@ivoanjo
Copy link
Author

ivoanjo commented Jun 27, 2022

Would still be nice to have this!

@stale stale bot removed the status: stale label Jun 27, 2022
@gilbertojrequena
Copy link
Contributor

This seems like an interesting feature, I would spend some time on it, if the team makes a decision on it.

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

4 participants