ai-landing-tutorial

测试规范(通用 rule 模板)

测试规范:命名、结构、禁止行为。放 .claude/rules/testing.md,AI 写测试时自动遵守。

基本原则

结构:Given-When-Then

每个测试只测一个场景,用 Given-When-Then 组织:

@Test
void test_save_success() {
    // Given:准备数据
    Entity e = new Entity();
    e.setName("test");
    // When:执行
    String id = service.save(e);
    // Then:断言
    assertNotNull(id);
}

命名规范

| 场景 | 命名示例 | |—|—| | 正常流程 | test_save_success | | 参数为空 | test_save_nullParam | | 数据不存在 | test_delete_notFound | | 边界条件 | test_list_largeOffset | | 异常情况 | test_save_duplicateKey |

测试数据准备

禁止行为

推荐做法


相关:service-dao.md(Service 层规范)、error-handling.md(异常处理)。