Dev Unit Test Writing Guide =========================== Create a unit testing guide for [language/framework] codebase. Project details: - Language: [JavaScript/Python/Java/other] - Test framework: [Jest/PyTest/JUnit/other] - Coverage target: [%] - Current coverage: [%] - Mocking library: [Jest mocks/unittest.mock/Mockito] UNIT TESTING GUIDE 1. WHAT TO TEST TEST THESE - Business logic functions - Data transformations - Error handling paths - Edge cases (empty/null/boundary values) - Each branch of conditionals - Public API of modules DO NOT TEST - Framework internals - Third-party libraries - Implementation details (test behavior not how) - Private methods directly 2. TEST STRUCTURE — AAA PATTERN ```javascript describe('calculateDiscount', () => { it('should apply 10% discount for premium users', () => { // ARRANGE const user = { type: 'premium' } const price = 100 // ACT const result = calculateDiscount(price, user) // ASSERT expect(result).toBe(90) }) }) ``` 3. NAMING CONVENTIONS Pattern: [unit]_[scenario]_[expected result] Examples: - calculateTax_withZeroIncome_returnsZero - validateEmail_withInvalidFormat_throwsError - getUser_withValidId_returnsUser - getUser_withMissingId_returns404 4. MOCKING DEPENDENCIES WHEN TO MOCK - External APIs - Database calls - File system - Date/time (for deterministic tests) - Random number generators ```javascript jest.mock('../services/emailService') const emailService = require('../services/emailService') emailService.send.mockResolvedValue({ success: true }) ``` 5. EDGE CASES TO ALWAYS TEST - Null/undefined inputs - Empty string/array/object - Zero values - Negative numbers - Very large numbers - Special characters in strings - Boundary values (min/max) 6. TEST QUALITY CHECKLIST ☐ Each test has one assertion focus ☐ Tests are independent (no shared state) ☐ Tests run in any order ☐ No network calls in unit tests ☐ Tests are fast (under 100ms each) ☐ Test names explain what is being tested ☐ Failure message is clear 7. COVERAGE GUIDE - Line coverage: [% target] - Branch coverage: [% target — more important] - Focus: critical paths over 100% coverage - Exclude: generated code/config files Source: https://promptzyo.com/prompt/dev-unit-test-writing-guide