Plan and implement a module test suite around risks, dependencies and failure behavior.
Design a test suite for a module with dependencies. Cover meaningful user-visible behavior across the module boundary rather than only one isolated function. ## Inputs Module API and code: [MODULE] Dependency contracts (what each dependency returns, throws or times out with): [DEPENDENCIES] Framework and fixtures (for example Vitest, Jest, pytest, node:test) and an example of an existing test: [FRAMEWORK] Failure history or risk priorities: [RISKS] Command the project uses to run tests: [TEST_COMMAND] ## Instructions 1. List the module's observable contract: inputs, outputs, side effects, errors, retries, timeouts and cancellation. 2. Build a risk-to-case matrix. For each risk, give the case that would catch it and the expected observable result. 3. Substitute dependencies at the module boundary only (injected functions, fakes, or the framework's module mock), and only when the real dependency is slow, nondeterministic or external. Do not mock the module's own internals. 4. Cover representative success, invalid input, dependency failure, retry exhaustion and boundary values. Cover cancellation or time when the contract includes them, using controllable fakes rather than real sleeps. 5. Name tests by behavior. Use Arrange-Act-Assert. Comment only where the scenario is not obvious. 6. Identify cases that belong in integration tests instead (real network, database, file system). 7. Suggest one deliberate fault to inject (for example retrying a non-retryable error) and name the test that should catch it. ## Return 1. Risk-to-case matrix 2. Test file(s) in the stated framework and existing style 3. Fixture and fake setup 4. Cases deferred to integration tests 5. Fault-injection check 6. How to run the tests with the project's command ## Acceptance checks - Keep assertions tied to the contract. - Explain important untested behavior and proposed checks. - Do not assert a coverage score or passing execution without evidence. Say clearly that the tests have not been run unless I give you results. - Tests do not depend on wall-clock time, network or test order.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Framework: Node.js built-in test runner (node:test, node:assert/strict). Module: getUserWithRetry(id, { fetchUser, sleep, retries = 2, delayMs = 100 }). It rejects ids that are not positive integers with TypeError before calling fetchUser. It retries errors that are not HttpError, or HttpError with status >= 500, with delays of delayMs * 2^attempt. It throws an HttpError below 500 (for example 404) immediately and rethrows the last error once retries are exhausted. Risks: retry storms against the user service; masking 404s.Illustrative; not a recorded model run. A risk matrix with these cases: first-call success with no sleep; 503 then success with one 100 ms delay; 404 not retried (one call); three 5xx errors give up with the last 503 and delays [100, 200]; a network TypeError is treated as transient; ids 0, -1, 1.5 and '7' are rejected with zero dependency calls. fetchUser and sleep are injected stubs, so there is no real waiting. Real HTTP behavior is deferred to integration tests. The fault-injection check makes 4xx retryable and expects the 404 test to fail. The answer states the suite has not been run.
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Generate one React function component from your requirements, with typed props, accessible markup, relevant loading/error/empty states, a usage example and tests.
Review a file or snippet for correctness, security, performance and maintainability risks in a stated project context, with severity, evidence and fixes.
Turn an approved REST contract into framework-specific endpoint code, validation and tests.
Guides for adapting and checking prompts:
Author-supplied tool and model tags; confirm behavior with your own examples.
IDEs
Models