133-java-testing-acceptance-tests
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseJava acceptance tests from Gherkin
基于Gherkin的Java验收测试
Implement acceptance tests from Gherkin feature files. Given a .feature file in context, find @acceptance-tagged scenarios and implement happy-path tests with RestAssured, Testcontainers, and WireMock.
What is covered in this Skill?
- Parse Gherkin .feature files to find scenarios tagged @acceptance or @acceptance-tests
- Implement happy-path acceptance tests (one test per scenario)
- RestAssured for REST API testing (given/when/then, status codes, JSON body assertions)
- Testcontainers for databases (PostgreSQL, etc.) and Kafka
- WireMock for stubbing external REST APIs
- BaseAcceptanceTest base class with @BeforeAll coordinate propagation via System.setProperty
- Given-When-Then structure mapping Gherkin steps to setup, request, and assertions
- Maven dependencies: rest-assured, testcontainers, wiremock-standalone
Preconditions: (1) The Gherkin .feature file must be in context. (2) The project must NOT use Spring Boot, Quarkus, or Micronaut — for those frameworks, use @323-frameworks-spring-boot-testing-acceptance-tests or framework-specific rules.
Scope: Implements only happy-path scenarios. Use the reference for detailed examples and constraints.
从Gherkin feature文件实现验收测试。若上下文环境中存在.feature文件,查找带有@acceptance标记的场景,并使用RestAssured、Testcontainers和WireMock实现快乐路径测试。
本技能涵盖内容:
- 解析Gherkin .feature文件,查找带有@acceptance或@acceptance-tests标记的场景
- 实现快乐路径验收测试(每个场景对应一个测试用例)
- 使用RestAssured进行REST API测试(given/when/then语法、状态码校验、JSON断言)
- 使用Testcontainers操作数据库(如PostgreSQL等)和Kafka
- 使用WireMock模拟外部REST API
- 包含BaseAcceptanceTest基类,通过System.setProperty在@BeforeAll中传递坐标
- 将Gherkin的Given-When-Then结构映射到测试的初始化、请求和断言环节
- Maven依赖:rest-assured、testcontainers、wiremock-standalone
前置条件: (1) 上下文环境中必须存在Gherkin .feature文件。(2) 项目不得使用Spring Boot、Quarkus或Micronaut——针对这些框架,请使用@323-frameworks-spring-boot-testing-acceptance-tests或框架专属规则。
适用范围: 仅实现快乐路径场景。详情示例和约束请参考参考文档。
Constraints
约束条件
Before applying any acceptance test changes, ensure the Gherkin .feature file is in context and the project compiles. If compilation fails or the feature file is missing, stop immediately.
- PRECONDITION: The Gherkin .feature file MUST be in context; the project MUST NOT use Spring Boot, Quarkus, or Micronaut
- MANDATORY: Run or
./mvnw compilebefore applying any changemvn compile - SAFETY: If compilation fails, stop immediately and do not proceed
- VERIFY: Run or
./mvnw clean verifyafter applying improvementsmvn clean verify - BEFORE APPLYING: Read the reference for detailed examples, good/bad patterns, and constraints
在应用任何验收测试变更前,确保Gherkin .feature文件存在且项目可编译。若编译失败或feature文件缺失,请立即停止操作。
- 前置要求:上下文环境中必须存在Gherkin .feature文件;项目不得使用Spring Boot、Quarkus或Micronaut
- 强制要求:在应用任何变更前,执行或
./mvnw compilemvn compile - 安全规范:若编译失败,立即停止操作,不得继续
- 验证步骤:在应用优化后,执行或
./mvnw clean verifymvn clean verify - 应用前须知:阅读参考文档,了解详细示例、优劣实践模式和约束条件
When to use this skill
何时使用本技能
- Review Java code for acceptance tests
- Apply best practices for acceptance tests in Java code
- 评审Java验收测试代码
- 在Java代码中应用验收测试最佳实践
Reference
参考文档
For detailed guidance, examples, and constraints, see references/133-java-testing-acceptance-tests.md.
如需详细指导、示例和约束条件,请查看references/133-java-testing-acceptance-tests.md。