java
config_error
ai_generated
true
org.junit.jupiter.api.extension.TestInstantiationException: Test class [com.example.OuterTest$InnerTest] must be a static inner class
ID: java/junit-nested-test-not-inner
80%Fix Rate
83%Confidence
0Evidence
2025-04-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 8+ | active | — | — | — |
Root Cause
@Nested test classes must be static inner classes, but they are non-static.
generic中文
@Nested 测试类必须是静态内部类,但当前是非静态的。
Workarounds
-
95% success Add static modifier to inner class
@Nested static class InnerTest { @Test void test() { } } -
80% success Move test methods to outer class
// Remove @Nested and put tests directly in outer class
Dead Ends
Common approaches that don't work:
-
Removing @Nested annotation
60% fail
Loses organizational structure; tests may run but not nested.
-
Making outer class non-static
50% fail
Outer class must be static for @Nested to work.