跳到正文
cccskills
免费在 GitHub 公开

insurance-testing

Detailed testing standards for persistence, service, and controller layers

中文简介正在准备中。当前显示原文说明。

实测评分 未实测

查看安装方法

包含的文件(1)

  • SKILL.md4.8 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

When to use

Use this skill when creating or modifying tests in this project.

Core principles

  1. Use AAA structure in every test.
  2. Keep Act phase to one line in unit tests.
  3. Keep tests deterministic (no hidden time/env/network dependencies).
  4. Use descriptive method names that state scenario and expected behavior.
  5. 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: @SpringBootTest or @DataJpaTest with in-memory DB.
  • Optional: Testcontainers for infrastructure fidelity when in-memory DB is insufficient.

Persistence tests

Applies to repository/integration-style tests.

  1. Use transactional rollback per test class (@Transactional + @Rollback) to avoid side effects.
  2. Seed stable data via SQL scripts when needed (src/test/resources/sql/ + @Sql).
  3. After write operations (create/update/delete), call EntityManager.flush() before assertions.
  4. Verify DB state independently from ORM behavior whenever possible:
    • JdbcTestUtils.countRowsInTable
    • JdbcTestUtils.countRowsInTableWhere
  5. Keep shared constants and entity factories in a central InstanceProvider.
  6. Prefer fixed IDs/emails/names in test constants that match SQL seeds.
  7. File naming: <Entity>RepositoryTest.

Persistence example

@Transactional
@Rollback
@SpringBootTest
class UserRepositoryTest {

    private static final String EMAIL = "test@example.com";

    @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).

  1. Use Mockito JUnit integration (@ExtendWith(MockitoExtension.class)).
  2. Mock collaborators with @Mock.
  3. Build subject with @InjectMocks.
  4. Stub only what the scenario needs.
  5. Use assertThrows for failure scenarios.
  6. 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.

  1. For request logic/helpers, prefer Mockito unit tests.
  2. For endpoint contract and MVC behavior, use @WebMvcTest + MockMvc.
  3. Mock auth/request objects as needed.
  4. If entity IDs are generated and lack setters, use local test helpers (reflection-based if required).
  5. 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.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Complete architecture reference for the A3 insurance platform — file locations, data flow, conventions, microservice map, and fullstack patterns

中文简介正在准备中。当前显示原文说明。

FDU-INS/Insurance-Skills792026年7月12日 更新

Drafts U.S. commercial real estate access and indemnity (right-of-entry) agreements for pre-closing due diligence. Covers license grants, non-invasive vs invasive testing gates, insurance/endorsement requirements, indemnity with discovery carve-outs, restoration and lien remedies, confidentiality, and anti-indemnity guardrails. Trigger: access agreement, right of entry, due diligence access, Phase I/II, invasive testing, pre-PSA site inspection.

中文简介正在准备中。当前显示原文说明。

FDU-INS/Insurance-Skills792026年7月12日 更新

当用户需要对意外险投保问卷进行专业、结构化的核保审查,提取职业类别、工作环境、作业内容、危险活动参与情况、交通出行习惯、特殊工作暴露及其他可能影响意外险承保判断的高风险信息,并生成适合意外险核保、补问流转和风险分层处理的结构化分析结果时使用本 skill。

中文简介正在准备中。当前显示原文说明。

FDU-INS/Insurance-Skills792026年7月12日 更新

Inspect, schema, and fill true AcroForm PDFs using sciClaw's pdf_form_inspect, pdf_form_schema, and pdf_form_fill tools. Use when: (1) checking whether a PDF is a real fillable AcroForm, (2) listing form field names, types, and choices, (3) filling a supported form from structured values, (4) preparing reviewable insurance, legal, administrative, or clinical form drafts, (5) reporting skipped fields or unused input keys after a fill. Do not use for scanned PDFs, OCR tasks, or XFA-only forms.

中文简介正在准备中。当前显示原文说明。

FDU-INS/Insurance-Skills792026年7月12日 更新

Guide actuarial analysis for insurance pricing. TRIGGERS - Use when user needs help with actuarial-analysis related tasks.

中文简介正在准备中。当前显示原文说明。

FDU-INS/Insurance-Skills792026年7月12日 更新

Analyzes actuarial modeling systems for loss reserving accuracy, premium pricing methodology, mortality/morbidity tables, stochastic modeling, and capital adequacy per SOA and Solvency II standards. USE THIS SKILL WHEN: - You need to review or audit actuarial models (reserving, pricing, capital) - Someone asks about loss triangle analysis or reserve adequacy - You are evaluating IBNR calculations, chain ladder methods, or Bornhuetter-Ferguson - A project involves insurance pricing, GLM rating models, or ratemaking - You need to assess Solvency II SCR calculations or RBC compliance - Someone mentions actuarial opinions, ASOP compliance, or SOA standards - You are reviewing stochastic models, ESG configurations, or DFA frameworks - A codebase uses actuarial libraries (chainladder, lifetables, ChainLadder R package) TRIGGER PHRASES: "actuarial", "loss reserving", "IBNR", "chain ladder", "premium pricing", "mortality table", "Solvency II", "capital adequacy", "ratemaking", "GLM pricing", "risk-based capital", "reserve analysis", "actuarial opinion"

中文简介正在准备中。当前显示原文说明。

FDU-INS/Insurance-Skills792026年7月12日 更新

查看 FDU-INS 的全部技能

报告此技能的问题