Skip to content

Commit fc652b5

Browse files
authored
Merge pull request #6 from MyFriendBen/pat/rfc-program-testing-strategy
Program Testing Strategy
2 parents beda6c7 + 4d2062f commit fc652b5

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# RFC 0008: Program Testing Strategy
2+
3+
Status: Discussion
4+
Author: Patrick Wey
5+
Created: 2025-10-15
6+
PR: [#6](https://github.com/MyFriendBen/rfc/pull/6)
7+
8+
## Summary
9+
10+
This RFC aims to establish an approach, including standards, tooling, and processes, for testing new benefit programs. This will ensure reliability and maintainability as we scale program additions across multiple states and white label configurations.
11+
12+
## Background
13+
14+
As we scale our screener, program additions are one of our primary feature development activities. Currently, testing for new programs is ad-hoc and inconsistent, leading to several challenges:
15+
16+
**Current State**: Programs are tested manually during development and QA. Limited automated test coverage exists for eligibility calculations, value computations, and program-specific business logic. This creates risk when modifying shared code or refactoring program logic.
17+
18+
**Problems**: Without systematic testing, we lack confidence in initial releases and subsequent changes. Regressions in program eligibility go undetected until production. Manual testing effort scales linearly with program count, becoming unsustainable.
19+
20+
**Motivation**: Implementing a comprehensive testing strategy now—before further scaling—will compound benefits: faster development cycles, reduced production bugs, and easier refactoring. This RFC establishes testing as a first-class requirement for program development.
21+
22+
## Proposal
23+
24+
Implement a testing strategy that emphasizes unit testing (Unit > Integration > E2E) and with specific standards for backend and frontend code. Use fixture-based testing to isolate external API dependencies (PolicyEngine) and enable fast, reliable test execution.
25+
26+
## Implementation
27+
28+
### Backend Testing
29+
30+
**Unit Tests**: Test program eligibility and value calculation logic in isolation.
31+
32+
**Integration Tests**: Test API endpoints, multi-model interactions, and service layer operations. Use `vcrpy` fixtures for PolicyEngine calls. Verify correct request formation and response handling.
33+
34+
### Frontend Testing
35+
36+
**Unit Tests**:
37+
There isn't much (if any) FE code added per program, but there are a few core behaviors that we should add tests for as a one-off task:
38+
- Test pure business logic functions for income calculations (`calcIncomeStreamAmount`, `calcMemberYearlyIncome`, `calcTotalIncome`) and value formatting (`programValue`, `calculateTotalValue`).
39+
40+
**Integration Tests**: Test english translations, program configuration, and "current benefit" flows. Use Playwright with HAR recording for backend API fixtures to enable offline testing.
41+
42+
### E2E Testing
43+
44+
Ues existing patterns to write a limited number smoke tests per white label configuration. Tests run against dev/staging databases without fixtures to catch integration issues. Implement a periodic cleanup job to remove test records.
45+
46+
### Code Coverage
47+
48+
**Tools**:
49+
- Backend: `coverage.py` for Python coverage reporting
50+
- Frontend: Istanbul/nyc (existing)
51+
- CI: CodeCov (free for open source) for tracking trends and (optionally) README badges
52+
53+
## Rollout Plan
54+
55+
## Phase 1
56+
- Ensure all tests run in CI
57+
* Add GH workflow to run BE test suite
58+
* Add GH workflow to run FE unit tests
59+
* Fix/Comment out existing test failures
60+
- Add coverage tooling
61+
* Add `coverage.py` for BE coverage reporting
62+
* Add GH workflow to upload BE coverage report to CodeCov
63+
* Add GH workflow to upload FE coverage report to CodeCov
64+
- Add TX programs using testing strategy
65+
* Add `vcrpy` for API fixture generation
66+
* Add fixture refresh automation
67+
68+
## Phase 2
69+
- Enforce testing coverage requirement for new code
70+
- Add unit tests for core FE logic (not program/white-label specific)
71+
- Translate validations into tests (using TX as a guide)
72+
- Implement E2E test data cleanup job
73+
74+
## Open Questions
75+
76+
1. **Fixture refresh cadence**: Nightly vs. weekly? Weekly reduces API load but may miss breaking changes sooner.
77+
2. **Test data cleanup frequency**: How often should we purge E2E test records from dev/staging databases?
78+
3. **Phase 2 coverage threshold**: What's realistic for new code and a codebase-wide minimum?
79+
4. **Reflect**: Do we want to keep this around? I say no. It's expensive and we now have exclusively developers who don't know the tool maintaining these no-code tests.
80+
81+
## References
82+
83+
- Testing Pyramid: https://martinfowler.com/articles/practical-test-pyramid.html
84+
- vcrpy documentation: https://vcrpy.readthedocs.io/
85+
- Playwright HAR recording: https://playwright.dev/docs/network#record-and-replay-network-traffic
86+
- Django testing best practices: https://docs.djangoproject.com/en/stable/topics/testing/

0 commit comments

Comments
 (0)