# 生命周期方法执行异常：@BeforeAll 方法 'void setUp()' 必须为静态，除非测试类使用 @TestInstance(Lifecycle.PER_CLASS) 注解

- **ID:** `java/junit-lifecycle-method-not-static`
- **领域:** java
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在每次方法生命周期的测试类中，@BeforeAll 或 @AfterAll 方法不是静态的。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 8+ | active | — | — |

## 解决方案

1. **Make method static** (90% 成功率)
   ```
   @BeforeAll
static void setUp() {
    // static setup
}
   ```
2. **Use @TestInstance(Lifecycle.PER_CLASS)** (85% 成功率)
   ```
   @TestInstance(Lifecycle.PER_CLASS)
class MyTest {
    @BeforeAll
    void setUp() {
        // non-static setup
    }
}
   ```

## 无效尝试

- **Adding static keyword without changing method logic** — Method may access instance fields which are not allowed. (60% 失败率)
- **Removing @BeforeAll annotation** — Setup logic won't run, causing test failures. (70% 失败率)
