Unit Testing Standard
Purpose
Section titled “Purpose”Unit tests provide the fastest reliable feedback on business logic, validation, authorization, state transitions, and error handling.
Nexa runner standard
Section titled “Nexa runner standard”| Repository family | Required runner | Supporting libraries |
|---|---|---|
nexa-web / React | Vitest | Testing Library, user-event, jsdom |
nexa-backend / Node.js TypeScript | Vitest | Vitest mocks/fakes and repository test utilities |
| FastAPI / Python | Pytest | pytest-cov, fixtures, parametrization |
Jest is not an approved Nexa baseline for nexa-web or nexa-backend.
Mandatory rules
Section titled “Mandatory rules”- Unit tests run on every pull request.
- Tests are deterministic and do not require live cloud services.
- External SDKs, clocks, random sources, queues, databases, and networks are isolated through adapters, controlled fakes, or test containers at the appropriate layer.
- A defect fix includes a regression test where technically feasible.
- A failing unit test blocks merge.
- Results are exported in a CI-readable format and coverage is exported as LCOV or Cobertura/XML as required by SonarQube.
Coverage interpretation
Section titled “Coverage interpretation”Coverage supports review and risk assessment; it is not a target to game. New and changed code should carry meaningful tests for critical paths and negative behavior. SonarQube consumes the coverage report generated by Vitest or Pytest; SonarQube does not execute the tests.
Boundary with deployed testing
Section titled “Boundary with deployed testing”Vitest and Pytest are the source-CI merge gates. Browser/E2E, API/contract, integration, Playwright, and Allure evidence belongs after deployment to a lower environment and does not replace unit testing.
Common failure modes
Section titled “Common failure modes”Over-mocking implementation detail, sleeping for timing, sharing mutable fixtures, asserting only happy paths, and making live platform calls create slow and unreliable suites.