You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider supporting static @Nested test classes #4622
It would be great if JUnit could support @Nested static classes.
Currently, only inner classes (non-static nested classes) are supported for @Nested execution.
It has several drawbacks:
static fields, methods, and interfaces are not allowed inside inner classes in Java 8. It causes issues if users want their test code to be executable with Java 8. For the time being, https://github.com/pgjdbc/pgjdbc uses both JUnit 5, and it supports a Java 8 runtime.
Testcontainers-java has quite a few JUnit4 Enclosed tests which use static nested classes, and it would be great if JUnit could allow upgrading without rewriting the tests to non-static. At least, it is not clear why non-static would be better there.
inner classes might accidentally access the scope of the outer class, so it makes sense making the class static unless it explicitly wants accessing the state of the outer instance.
As per @marcphilipp's comment, currently JUnit treats static nested classes as if they were just regular top-level classes. It might be if JUnit allows @Nested static class, the discovery should be updated to prevent the class to be treated as both top-level and nested.
Activity
[-]Consider allowing static @Nested classes[/-][+]Consider supporting static `@Nested` test classes[/+]