Document module behavior from its test suite

Extract clear business rules, accepted inputs, and edge cases for undocumented modules solely from their test suites.

You getModule Purpose, expected Inputs & Preconditions and verified Business Rules & Invariants

Prompt

Prompt
Act as a software engineer reverse-engineering an undocumented module from its unit and integration tests.
- Analyze the pasted test code to extract explicit behaviors, edge cases, and constraints.
- Ignore test-only harness details like mock setups or spy assertions unless they reveal a dependency interface.
- Translate test assertions into plain-language business rules and functional specifications.
- Flag undocumented assumptions or gaps where tests fail to assert expected edge cases.
Output format:
1. Module Purpose (1-2 sentences on what problem this module solves)
2. Expected Inputs & Preconditions (bulleted list)
3. Verified Business Rules & Invariants (numbered list of proven behaviors)
4. Error Handling & Edge Cases (how failures are handled)
5. Untested Blind Spots (missing tests or unverified boundaries)
Here is the test suite code:

Example output

Example for: Discount calculation test file in an e-commerce engine

1. Module Purpose

This module calculates shopping cart discounts, applying promotional coupon codes, member tier reductions, and maximum capping rules prior to payment checkout.

2. Expected Inputs & Preconditions
  • Cart object containing items with non-negative prices and integer quantities.
  • Optional customer profile containing loyalty tier (BRONZE, SILVER, GOLD).
  • Optional single promo code string.
3. Verified Business Rules & Invariants
  1. Fixed-amount coupons apply before percentage-based membership discounts.
  2. VIP discounts do not apply to items already marked as clearance.
  3. Total discount amount cannot exceed 50% of the original subtotal under any condition.
  4. Shipping fees are added after discounts are calculated and cannot be discounted by coupons.
4. Error Handling & Edge Cases
  • Invalid or expired coupons throw a custom InvalidCouponException and leave cart subtotal untouched.
  • Carts with a subtotal of $0.00 bypass all calculations without raising errors.
5. Untested Blind Spots
  • No test asserts behavior when multiple conflicting coupons are provided.
  • No boundary test for floating-point rounding precision when percentage splits produce fractional cents.
Written by AI from this prompt. Your results will vary.

Copy test files (e.g., Jest, PyTest, or Go test files) into Claude, ChatGPT, or Gemini. Ask the model to generate the corresponding interface docstrings or TypeScript type definitions based on the output.

Make it repeatable

Keep using this prompt without pasting it in every time.

Keep exploring

More in Coding