# Cosmic Unit Test Guidance

Use for Cosmic-family Java modules that follow common, business, opplugin, and formplugin project structure.

## Project Structure

- `<module>-common`: constants, enums, POJO, DTO, utility classes.
- `<module>-business`: static helpers and business services.
- `<module>-opplugin`: validators, operation plugins, conversion plugins.
- `<module>-formplugin`: form, list, and bill plugins.

## Test Routing

- Common POJO/DTO: instantiate directly, no static mocks.
- Common enum: test lookup and match methods.
- Business helper: mock static service helpers and verify outputs or side effects.
- Validator: collect validation messages and cover declared field preparation.
- Operation plugin: test transaction data packets, field declarations, and operation results.
- Form plugin: use the module's `BasePluginTest` or existing tests to obtain view/model mocks.

## Mock Rules

- Mock static helpers such as `QueryServiceHelper`, `BusinessDataServiceHelper`, `OperationServiceHelper`, `SaveServiceHelper`, `BaseDataServiceHelper`, `SystemParamServiceHelper`, and `ResManager` only when the code imports or calls them.
- Close every `MockedStatic` in teardown.
- Do not duplicate mocks already provided by the module's base test.
- Mock `kd.bos.db.DB` only after defrost handling if the project requires it.
- Some project helpers require custom test helper mocks; do not replace those with generic static mocks without checking existing tests.

## Assertion Rules

- Every test must assert a real output, side effect, exception, or mock interaction.
- Do not use tautological assertions such as `assertTrue(true)`.
- Cover switch cases as separate tests.
- Cover boundary values around comparisons, empty collections, one row, and multiple rows.
- If source code appears buggy, write the expected correct behavior and call out that the test exposes the bug.
