PromptBase
PromptBase SelectGet Select
Close icon
General
Home
Marketplace
Create
Hire
Login
Chat
Sell
Explore

Prompt Details

Model
(claude-5-5-sonnet)
Token size
3,737
Example input
[CODEBASE_CONTEXT]: Language: Python 3.12 Framework: FastAPI Test Framework: Pytest Module: discount_service.py [SOURCE_CODE]: def calculate_discount(price, discount_percent): if price < 0: raise ValueError("Price cannot be negative") if discount_percent < 0 or discount_percent > 100: raise ValueError("Invalid discount") return price - (price * discount_percent / 100) [EXISTING_TESTS]: No existing tests. No fixtures. No mocking utilities. [REQUIREMENTS_AND_BUGS]: Price cannot be negative. Discount must be between 0% and 100%. A 20% discount on β‚Ή1,000 must return β‚Ή800. Invalid values must raise appropriate exceptions. [COVERAGE_AND_CONSTRAINTS]: No coverage report. Tests must run locally. No production database required.
Example output
### 1\. πŸ“Š Executive Summary Testing scope defined The target is a discount calculation function used in an e-commerce application. Initial assessment: | Area | Assessment | | --------------------- | ---------------- | | Input validation | Needs testing | | Discount calculation | Needs testing | | Boundary conditions | Needs testing | | Exception handling | Needs testing | | Integration | Not yet verified | | Regression protection | Not established | | Coverage | Not measured | Primary risks: * Incorrect discount calculations. * Negative prices being accepted. * Discounts exceeding 100%. * Incorrect handling of zero values. * Unexpected input types causing uncontrolled errors. ### 2\. πŸ—οΈ Codebase and Framework Summary | Component | Confirmed details | | ------------- | ------------------------------ | | Language | Python 3.12 | | Framework | FastAPI (project context) | | Test runner | Pytest | | Target module | discount_service.py | | Database | Not required for this function | | Mocking | Not required for unit tests | | Coverage tool | pytest-cov (recommended) | Assumptions: FastAPI integration is not demonstrated because no API endpoint was supplied. The function itself can be tested independently. ### 3\. 🧩 Behavior and Test Mapping | Code component | Expected behavior | Test cases | | -------------------- | --------------------------- | ---------- | | Price validation | Reject negative prices | UT-001 | | Discount validation | Reject below 0% | UT-002 | | Discount validation | Reject above 100% | UT-003 | | Discount calculation | Calculate correctly | UT-004 | | Zero discount | Return original price | UT-005 | | Full discount | Return zero | UT-006 | | Decimal calculation | Preserve expected precision | UT-007 | | Invalid data types | Define and verify behavior | UT-008 | ### 4\. πŸ§ͺ Generated Unit Tests 8 proposed test scenarios Test file: `tests/test_discount_service.py` ```python import pytest from discount_service import calculate_discount def test_calculate_standard_discount(): result = calculate_discount(1000, 20) assert result == 800 def test_reject_negative_price(): with pytest.raises( ValueError, match="Price cannot be negative" ): calculate_discount(-100, 20) def test_reject_negative_discount(): with pytest.raises( ValueError, match="Invalid discount" ): calculate_discount(1000, -10) def test_reject_discount_above_100(): with pytest.raises( ValueError, match="Invalid discount" ): calculate_discount(1000, 120) def test_zero_discount(): result = calculate_discount(1000, 0) assert result == 1000 def test_full_discount(): result = calculate_discount(1000, 100) assert result == 0 def test_decimal_discount(): result = calculate_discount(999, 15) assert result == pytest.approx(849.15) def test_zero_price(): result = calculate_discount(0, 20) assert result == 0 ``` Why these tests matter: * Normal calculation verifies the main business logic. * Negative values verify input validation. * Zero and 100% discounts verify boundaries. * Decimal calculation verifies numerical correctness. * Zero price verifies an important edge case. ### 5\. πŸ”— Generated Integration Tests Current limitation: No API endpoint or application integration code was supplied. Recommended integration scenario: `POST /calculate-discount` Example request: ```json { "price": 1000, "discount_percent": 20 } ``` Expected response: ```json { "original_price": 1000, "discount_percent": 20, "final_price": 800 } ``` Recommended integration assertions: * API accepts valid requests. * API returns the correct calculated amount. * API rejects invalid discount values. * API returns the documented HTTP status codes. * API does not expose internal exception details. These are implementation specifications, not executable integration tests because the endpoint has not been supplied. ### 6\. ⚠️ Edge-Case Test Catalog | ID | Scenario | Expected behavior | | ------ | ----------------- | ------------------------------------- | | EC-001 | Price = 0 | Return 0 | | EC-002 | Discount = 0 | Original price | | EC-003 | Discount = 100 | Return 0 | | EC-004 | Discount = -0.01 | Reject | | EC-005 | Discount = 100.01 | Reject | | EC-006 | Price = -0.01 | Reject | | EC-007 | Very large price | Calculate without unexpected overflow | | EC-008 | Empty input | Clarify API contract | | EC-009 | String price | Define type-validation behavior | | EC-010 | Boolean price | Explicitly reject or define behavior | Important finding: Python treats booleans as integers. Therefore, `True` could currently be accepted as a price. This deserves a dedicated validation requirement and regression test. ### 7\. 🏭 Fixtures and Test Data Package A reusable fixture can simplify future testing. ```python import pytest @pytest.fixture def standard_discount_data(): return { "price": 1000, "discount_percent": 20, "expected": 800 } ``` Usage: ```python def test_discount_with_fixture(standard_discount_data): data = standard_discount_data result = calculate_discount( data["price"], data["discount_percent"] ) assert result == data["expected"] ``` Fixture characteristics: * Purpose: Reusable standard discount data. * Defaults: Price β‚Ή1,000, discount 20%. * Variations: Zero discount, full discount, decimal discount. * Cleanup: Not required. * Reuse: Unit tests for discount calculations. ### 8\. 🎯 Assertion and Mocking Quality Audit | Check | Result | | ------------------------ | -------------- | | Correct return value | Included | | Exception validation | Included | | Boundary assertions | Included | | Decimal precision | Included | | Mock verification | Not required | | Side-effect verification | Not applicable | | API response assertions | Pending | Recommended improvement: Use `pytest.approx()` for floating-point results instead of relying on exact floating-point equality. Avoid unnecessary mocks because the function has no external dependencies. ### 9\. πŸ“ˆ Coverage Gap Report Coverage not measured No coverage report or execution results were supplied. Qualitative assessment: | Coverage category | Assessment | | ------------------------ | ---------- | | Normal execution | Proposed | | Negative price branch | Proposed | | Invalid discount branch | Proposed | | Boundary coverage | Proposed | | Exception coverage | Proposed | | API integration coverage | Missing | | Type-validation coverage | Missing | Do not interpret these proposed tests as measured coverage. Coverage command: ```bash pytest --cov=discount_service \ --cov-report=term-missing ``` ### 10\. πŸ› Regression Test Plan Three important regression scenarios: REG-001: Incorrect discount calculation * Input: β‚Ή1,000, 20%. * Expected: β‚Ή800. * Detects: Incorrect percentage calculation. REG-002: Negative discount accepted * Input: β‚Ή1,000, -10%. * Expected: `ValueError`. * Detects: Missing validation. REG-003: Discount above 100% * Input: β‚Ή1,000, 150%. * Expected: `ValueError`. * Detects: Invalid discount acceptance. These tests protect against recurrence of the identified risks. No historical defect was supplied. ### 11\. πŸ” Reliability and Security Tests Recommended checks: * Reject unexpected input types. * Reject negative prices. * Prevent invalid discount percentages. * Avoid exposing internal errors through API responses. * Ensure calculations do not depend on system time. * Use deterministic test data. * Avoid production customer data. Potential security concern: If this calculation is exposed through a public API, server-side validation must be enforced even if the frontend validates the same inputs. ### 12\. πŸ“ File and Directory Placement Recommended project structure: ```text ecommerce-project/ β”‚ β”œβ”€β”€ discount_service.py β”‚ β”œβ”€β”€ tests/ β”‚ β”œβ”€β”€ __init__.py β”‚ β”œβ”€β”€ test_discount_service.py β”‚ β”œβ”€β”€ test_discount_integration.py β”‚ β”‚ β”‚ └── fixtures/ β”‚ β”œβ”€β”€ __init__.py β”‚ └── discount_fixtures.py β”‚ β”œβ”€β”€ requirements.txt └── pytest.ini ``` Integration test files should be added when the API implementation exists. ### 13\. ▢️ Test Execution Instructions Step 1: Install dependencies ```bash pip install pytest pytest-cov ``` Step 2: Run unit tests ```bash pytest tests/test_discount_service.py -v ``` Step 3: Run the complete suite ```bash pytest -v ``` Step 4: Generate coverage report ```bash pytest --cov=discount_service --cov-report=html ``` Step 5: Inspect the report Open: ```text htmlcov/index.html ``` Actual test results must be obtained by executing these commands. ### 14\. πŸ› οΈ Test Failure Troubleshooting | Failure | Possible cause | Investigation | | --------------------- | ------------------------- | ------------------------------ | | ModuleNotFoundError | Import path issue | Check project root | | AssertionError | Incorrect calculation | Inspect function output | | ValueError not raised | Missing validation | Inspect conditions | | ImportError | Dependency issue | Check installation | | Test collection error | Incorrect test structure | Inspect test names and imports | | Coverage missing | Incorrect coverage target | Verify module name | Never modify expected results just to make tests pass. ### 15\. 🚦 Prioritized QA Improvement Roadmap | Priority | Action | Effort | | -------- | --------------------------------------------------------------- | ------------- | | P0 | Validate financial calculation boundaries before production use | 1–2 hours | | P1 | Add complete unit tests | 1 hour | | P1 | Add explicit input-type validation | 1–2 hours | | P2 | Add API integration tests | 2–4 hours | | P2 | Introduce reusable fixtures | 30–60 minutes | | P3 | Add property-based testing | 2–3 hours | Effort estimates assume a small existing Python project and exclude major infrastructure work. Acceptance criteria: * All specified valid inputs produce correct results. * Invalid values are rejected. * Boundary conditions are tested. * Tests execute deterministically. * Coverage is measured. * Integration behavior is verified when the API becomes available. ### 16\. πŸ† Final Implementation Blueprint Implementation plan ready Recommended deliverables: | Deliverable | Status | | ------------------------------ | ------------------------------ | | Source-code analysis | Complete for supplied function | | Unit test code | Generated | | Integration test specification | Generated | | Edge-case catalog | Generated | | Fixtures | Generated | | Assertion audit | Completed | | Coverage assessment | Qualitative | | Regression plan | Generated | | Security test recommendations | Generated | | Execution instructions | Generated | | QA roadmap | Generated | Final limitations: * Only the supplied function was analyzed. * No actual repository was inspected. * No tests were executed. * No measured coverage percentage is available. * API integration tests require actual endpoint code. * Input-type behavior requires an explicit requirement before changing the implementation. ### 🎯 FINAL QA VERDICT Sample test assessment Package generated ### 8 Proposed executable unit-test scenarios * Unit testing: Generated * Integration testing: Specification ready * Edge-case analysis: Completed * Regression planning: Completed * Coverage verification: Pending execution * Production readiness: Not established Conclusion: The proposed test suite covers the main calculation logic, validation rules, and important boundaries. Before production release, strengthen input-type validation and verify API integration behavior. Sample Test 01 completed. 😊
Claude

Automated Test Suite Qa Engineer

Add to Cart
Instant accessInstant access
Usage rightsCommercial use
Money-back guaranteeMoney‑back
By purchasing this prompt, you agree to our terms of service
CLAUDE-5-5-SONNET
Tested icon
Guide icon
4 examples icon
Free credits icon
Transform existing source code into practical, maintainable automated tests that verify real behavior, expose edge cases, and improve software quality. The Automated Test Suite & QA Engineer helps software developers and QA engineers generate unit tests, integration tests, regression tests, reusable test fixtures, meaningful assertions, and a prioritized coverage improvement plan for an existing codebase.
...more
Added 2 days ago
Report
Browse Marketplace