testing-engineering — правило для Claude Code: тесты и установка
Правило testing-engineering для Claude Code задаёт требования к юнит-тестам, архитектуре проекта и зависимостям. Оно охватывает проектирование слоёв, обработку исключений и соглашения для моделей данных.
MIT ★ 517 обновлён 2026-11-16
.claude/rules/testing-engineering.mdЧто делает testing-engineering
Правило задаёт стандарты юнит-тестов и структуры проекта. Тесты должны запускаться автоматически, не зависеть друг от друга и давать повторяемый результат. Проверки охватывают граничные значения, корректные и ошибочные входные данные; результат теста подтверждают утверждениями, а не выводом в System.out. Для покрытия операторов задан порог от 70%, для ветвей — от 80%, а для основных модулей требуется 100%.
Документ описывает слои от Open API до DAO, распределяет обработку исключений и определяет роли DO, DTO, BO, Query и VO. Для внутренних зависимостей заданы формат GAV и правила версий: зависимости на SNAPSHOT запрещены. Для объектов с более чем тремя состояниями нужна диаграмма состояний; проектирование хранения и структур данных проходит ревью с документированием.
В Claude Code правило устанавливается копированием в .claude/rules/testing-engineering.md. Для других поддерживаемых IDE предусмотрены отдельные пути установки.
Какие задачи решает
- проверять независимость и повторяемость юнит-тестов
- задавать пороги покрытия операторов и ветвей
- разделять ответственность между слоями приложения
- согласовать обработку исключений по слоям
- запретить зависимости на версии
SNAPSHOT
Примеры запросов агенту
- Проверь юнит-тесты на соответствие правилам проекта.
- Оцени структуру приложения и обработку исключений по слоям.
- Проверь зависимости и диаграммы состояний по правилам проекта.
Как установить testing-engineering
Вручную: положить файлы
.claude/rules/testing-engineering.mdПоле paths во frontmatter ограничивает файлы
AGENTS.md
Codex читает AGENTS.md: вставьте текст правила туда
Вручную: положить файлы
.cursor/rules/testing-engineering.mdcВо frontmatter: description, globs, alwaysApply
Вручную: положить файлы
.github/instructions/testing-engineering.instructions.mdПоле applyTo задаёт, к каким файлам применять
Вручную: положить файлы
.devin/rules/testing-engineering.mdВручную: положить файлы
.clinerules/testing-engineering.mdПо шагам, с командами для каждой платформы: AGENTS.md и CLAUDE.md: что это, кто читает и какой выбрать
Вопросы о testing-engineering
Как установить testing-engineering в Claude Code?
Скопируйте правило в .claude/rules/testing-engineering.md.
Что делает testing-engineering?
Задаёт требования к юнит-тестам, покрытию кода, слоям приложения, обработке исключений и внутренним зависимостям.
Какие пороги покрытия задаёт testing-engineering?
Для покрытия операторов требуется не менее 70%, для ветвей — не менее 80%. Для основных модулей задано 100% покрытия операторов.
Исходный текст
testing-engineering.md · MIT
# Unit testing and project-structure guidelines
## Unit testing guidelines
### AIR principles
**Detection mode**: semantic
**Unit tests must follow the AIR principles (MULT-GEN-203):**
| Principle | Description |
|------|------|
| A - Automatic | Runs fully automatically without human intervention |
| I - Independent | Test cases are independent; they must not call or depend on each other |
| R - Repeatable | Repeatable, with stable and consistent results |
### Test conventions
**Detection mode**: semantic
```java
// Correct unit test (MULT-GEN-204)
@Test
public void testGetUserById() {
// Given: prepare test data
Long userId = 1L;
User expectedUser = new User(userId, "test");
when(userDao.findById(userId)).thenReturn(expectedUser);
// When: invoke the method under test
User actualUser = userService.getUserById(userId);
// Then: verify the result
assertNotNull(actualUser);
assertEquals(expectedUser.getName(), actualUser.getName());
}
```
### BCDE principles
**Detection mode**: semantic
| Principle | Description |
|------|------|
| B - Border | Boundary-value testing (loop boundaries, numeric boundaries) |
| C - Correct | Correct input produces the expected result |
| D - Design | Write tests together with the design document |
| E - Error | Erroneous input produces the expected error output |
### Test coverage (MULT-GEN-208)
**Detection mode**: semantic
- Statement coverage >= 70%
- Core-module statement coverage = 100%
- Branch coverage >= 80%
### Testing anti-patterns
**Detection mode**: semantic
```java
// Wrong: verify with System.out (MULT-GEN-204)
@Test
public void testBad() {
User user = userService.getUserById(1L);
System.out.println(user.getName()); // Forbidden!
}
// Correct: verify with asserts
@Test
public void testGood() {
User user = userService.getUserById(1L);
assertNotNull(user);
assertEquals("expected", user.getName());
}
// Wrong: test cases depend on each other (MULT-GEN-205)
@Test
public void testA() {
// Set a static variable
TestContext.value = 1;
}
@Test
public void testB() {
// Depends on testA's result
assertEquals(1, TestContext.value); // Forbidden!
}
```
## Project structure guidelines
### Application layering
**Detection mode**: semantic
**Standard layered architecture (MULT-GEN-193):**
```
Open API layer → Client display layer → Web layer → Service layer → Manager layer → DAO layer
```
| Layer | Responsibility | Description |
|------|------|------|
| Open API layer | Wraps Service and exposes RPC/HTTP interfaces | Gateway security control, traffic control |
| Client display layer | Template rendering and display | velocity, JS, JSP, mobile |
| Web layer | Access control and forwarding, basic parameter validation | No business reuse; keep processing simple |
| Service layer | Concrete business logic | Business encapsulation, composed calls |
| Manager layer | Common business processing, third-party preprocessing | Shared Service capabilities (cache, middleware), composition and reuse of multiple DAOs |
| DAO layer | Data access | MySQL, Oracle, Hbase, etc. |
### Exception handling by layer (MULT-GEN-194)
**Detection mode**: semantic
| Layer | Exception handling |
|------|-------------|
| DAO layer | catch → throw DAOException, no logging |
| Service layer | Must log to disk with parameter information |
| Manager layer | Like DAO when co-located; like Service when independently deployed |
| Web layer | Do not rethrow; redirect to a friendly error page |
| API layer | Convert to an error code + error message |
### Domain model conventions (MULT-GEN-195)
**Detection mode**: semantic
| Model | Description | Use case |
|------|------|---------|
| DO | Object corresponding to a database table | Passed upward by the DAO layer |
| DTO | Data transfer object | Passed outward by Service/Manager |
| BO | Business object | Business-logic encapsulation in the Service layer |
| Query | Query request object | Receives query parameters at each layer; Map is forbidden with more than 2 parameters |
| VO | Display-layer object | Passed from Web to the template engine |
### Internal library dependency conventions (MULT-GEN-196/197/198)
**Detection mode**: semantic
**GAV format conventions:**
| Convention | Description | Example |
|------|------|------|
| GroupID | com.{company/BU}.business-line.[sub-business-line] | `com.example.order` |
| ArtifactID | product-line-name-module-name | `passenger-order-api` |
| Version | major.minor.patch | `1.0.0` |
**Version numbering rules:**
| Version type | Description |
|---------|------|
| Major version | Incompatible API changes |
| Minor version | Backward-compatible feature additions |
| Patch version | Backward-compatible bug fixes |
**Dependency rules:**
```xml
<!-- Wrong: depend on a SNAPSHOT version -->
<dependency>
<version>1.0.0-SNAPSHOT</version> <!-- Forbidden! -->
</dependency>
<!-- Correct: depend on a release version -->
<dependency>
<version>1.0.0</version>
</dependency>
<!-- Correct: use a shared version variable -->
<dependency>
<version>${spring.version}</version>
</dependency>
```
### Design conventions (MULT-GEN-199/200/201/202)
**Detection mode**: semantic
| Rule | Description |
|------|------|
| Storage design review | Storage designs and data structures must be reviewed and documented |
| State diagrams | Use a state diagram when a business object has more than 3 states |
| Single responsibility | Class design follows the single-responsibility principle |
| Composition over inheritance | Prefer aggregation/composition; use inheritance cautiously |
© kyy-logs · MIT · kyy-logs/code-review-gate-skill