java
config_error
ai_generated
true
测试实例化异常:测试类 [com.example.OuterTest$InnerTest] 必须是静态内部类
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%修复率
83%置信度
0证据数
2025-04-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 8+ | active | — | — | — |
根因分析
@Nested 测试类必须是静态内部类,但当前是非静态的。
English
@Nested test classes must be static inner classes, but they are non-static.
解决方案
-
95% 成功率 Add static modifier to inner class
@Nested static class InnerTest { @Test void test() { } } -
80% 成功率 Move test methods to outer class
// Remove @Nested and put tests directly in outer class
无效尝试
常见但无效的做法:
-
Removing @Nested annotation
60% 失败
Loses organizational structure; tests may run but not nested.
-
Making outer class non-static
50% 失败
Outer class must be static for @Nested to work.