insurance-testing
БесплатноБез исполняемых скриптовНе проверенDetailed testing standards for persistence, service, and controller layers
от FDU-INS★ 84 звезды на GitHubОб этом скилле
When to use
Use this skill when creating or modifying tests in this project.
Core principles
- Use AAA structure in every test.
- Keep Act phase to one line in unit tests.
- Keep tests deterministic (no hidden time/env/network dependencies).
- Use descriptive method names that state scenario and expected behavior.
- Pick the narrowest useful test type:
- unit tests for pure business logic,
- slice tests for web/repository concerns,
- full integration only when cross-layer wiring matters.
Testing stack by layer
- Unit: JUnit 5 + Mockito.
- Controller slice:
@WebMvcTest+MockMvc. - Persistence/integration:
@SpringBootTestor@DataJpaTestwith in-memory DB. - Optional: Testcontainers for infrastructure fidelity when in-memory DB is insufficient.
Persistence tests
Applies to repository/integration-style tests.
- Use transactional rollback per test class (
@Transactional+@Rollback) to avoid side effects. - Seed stable data via SQL scripts when needed (
src/test/resources/sql/+@Sql). - After write operations (
create/update/delete), callEntityManager.flush()before assertions. - Verify DB state independently from ORM behavior whenever possible:
JdbcTestUtils.countRowsInTableJdbcTestUtils.countRowsInTableWhere
- Keep shared constants and entity factories in a central
InstanceProvider. - Prefer fixed IDs/emails/names in test constants that match SQL seeds.
- File naming:
<Entity>RepositoryTest.
Persistence example
@Transactional
@Rollback
@SpringBootTest
class UserRepositoryTest {
private static final String EMAIL = "[email protected]";
@PersistenceContext
private EntityManager em;
@Autowired
private UserRepository userRepository;
@Autowired
private DataSource dataSource;
private JdbcTemplate jdbcTemplate;
@BeforeEach
void setUp() {
jdbcTemplate = new JdbcTemplate(dataSource);
}
@Test
void testCreate() {
// Arrange
int before = JdbcTestUtils.countRowsInTable(jdbcTemplate, "users");
// Act
User user = userRepository.create(EMAIL, "secret", "John", "Doe");
em.flush();
// Assert
assertEquals(before + 1, JdbcTestUtils.countRowsInTable(jdbcTemplate, "users"));
assertNotNull(user);
}
}
Service tests
Pure unit tests (no Spring context).
- Use Mockito JUnit integration (
@ExtendWith(MockitoExtension.class)). - Mock collaborators with
@Mock. - Build subject with
@InjectMocks. - Stub only what the scenario needs.
- Use
assertThrowsfor failure scenarios. - File naming:
<Service>ImplTest.
Service example
@ExtendWith(MockitoExtension.class)
class UserServiceImplTest {
private static final long USER_ID = 1L;
@InjectMocks
private UserServiceImpl userService;
@Mock
private UserRepository userRepository;
@Test
void testFindByIdExistingUser() {
// Arrange
when(userRepository.findById(USER_ID)).thenReturn(Optional.of(new User()));
// Act
Optional<User> result = userService.findById(USER_ID);
// Assert
assertTrue(result.isPresent());
}
@Test
void testFindByIdNonExisting() {
// Arrange
when(userRepository.findById(anyLong())).thenReturn(Optional.empty());
// Act
Optional<User> result = userService.findById(1L);
// Assert
assertFalse(result.isPresent());
}
}
Controller tests
Use Mockito helpers or slice tests based on scope.
- For request logic/helpers, prefer Mockito unit tests.
- For endpoint contract and MVC behavior, use
@WebMvcTest+MockMvc. - Mock auth/request objects as needed.
- If entity IDs are generated and lack setters, use local test helpers (reflection-based if required).
- File naming:
<Entity>ControllerTest.
Controller helper pattern
private User createUserWithId(String email, Long id) throws Exception {
User user = new User(email);
Field idField = User.class.getDeclaredField("id");
idField.setAccessible(true);
idField.set(user, id);
return user;
}
Keep small helper methods (createUserWithId, createMockAuthentication, etc.) inside the test class to reduce
duplication and improve readability.
Test review checklist
- AAA shape is explicit.
- Act phase is one line (unit tests).
- Assertions validate outcome and important side effects.
- Collaborator interactions are verified only when behaviorally relevant.
- Test names and fixtures clearly express intent.
- Repository tests flush before asserting persisted state.
- Controller tests cover validation/error paths for request boundaries.
Установить insurance-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл insurance-testing?
Detailed testing standards for persistence, service, and controller layers
Как установить скилл insurance-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл insurance-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic