testing
Consistent test structure for service and controller layers. Use when writing any new test or adding coverage.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Consistent test structure for service and controller layers. Use when writing any new test or adding coverage.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Team quality gate as executable instruction. Use when reviewing completed work before merge, or when processing PR review comments received from other reviewers.
Generate well-formed user stories from technical context. Use when generating or improving story descriptions for an issue tracker.
Type-safe validated configuration properties from application.yml. Use when adding any externalisable value.
Consistent error handling with named exceptions and global handler. Use when implementing any method that can fail with a business reason.
Consistent, safe log statements with correct levels and no PII. Use when adding or reviewing log statements.
Team standard for improving existing code without changing behaviour. Use when refactoring code.
| name | testing |
| description | Consistent test structure for service and controller layers. Use when writing any new test or adding coverage. |
When to load it: When writing any new test, or adding test coverage to an existing feature.
Produces unit tests for the service layer (plain JUnit + Mockito, no Spring context) and
integration tests for the controller layer (@WebMvcTest). Enforces a consistent naming
convention and test structure.
Unit tests (service layer):
Controller tests:
@WebMvcTest. Do not load the full Spring context.MockMvc. Assert HTTP status and response body shape.@MockBean.Naming: methodName_condition_expectedResult
Example: getById_unknownId_returns404
Unit test:
@ExtendWith(MockitoExtension.class)
class [Resource]ServiceTest {
@Mock
private [Dependency] dependency;
@InjectMocks
private [Resource]Service service;
@Test
void [methodName]_[condition]_[expectedResult]() {
// Arrange
given(dependency.[method]()).willReturn([value]);
// Act
[ReturnType] result = service.[method]([args]);
// Assert
assertThat(result).[assertion];
}
}
Controller test:
@WebMvcTest([Resource]Controller.class)
class [Resource]ControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private [Resource]Service service;
@Test
void [methodName]_[condition]_[expectedResult]() throws Exception {
given(service.[method]([args])).willReturn([value]);
mockMvc.perform(get("/api/v1/[resource]/{id}", [id]))
.andExpect(status().isOk())
.andExpect(jsonPath("$.field").value([expected]));
}
}
@SpringBootTest for tests that only need one layer@WebMvcTest is fortest prefix or should — use method_condition_result