# 测试超时：测试在 5000 毫秒后超时

- **ID:** `java/junit-test-execution-timeout`
- **领域:** java
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

测试方法执行时间超过指定的超时时间，原因可能是无限循环、阻塞调用或性能缓慢。

## 版本兼容性

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

## 解决方案

1. **Debug with stack trace on timeout** (85% 成功率)
   ```
   // Add @Timeout annotation and check thread dump on failure
@Timeout(5)
@Test
void slowTest() {
    // code
}
   ```
2. **Use assertTimeout with preemptive flag** (90% 成功率)
   ```
   assertTimeoutPreemptively(Duration.ofSeconds(5), () -> {
    // test code
});
   ```

## 无效尝试

- **Increasing timeout value without investigation** — May hide performance bugs or infinite loops. (70% 失败率)
- **Removing @Timeout annotation** — Test may run indefinitely in CI. (60% 失败率)
