Generate thorough unit tests for AWS Python business logic with full branch coverage, boundary value analysis, and edge case testing. Isolates pure logic from AWS dependencies using mocks. Covers every if/elif/else, try/except, guard clause, loop variant, and data transformation. Uses pytest parametrize for boundary testing and hypothesis for property-based testing. Use when asked to write unit tests, test business logic, test all branches, test edge cases, improve coverage, or test a specific function for any AWS Python project.
Installation
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Generate thorough unit tests for AWS Python business logic with full branch coverage, boundary value analysis, and edge case testing. Isolates pure logic from AWS dependencies using mocks. Covers every if/elif/else, try/except, guard clause, loop variant, and data transformation. Uses pytest parametrize for boundary testing and hypothesis for property-based testing. Use when asked to write unit tests, test business logic, test all branches, test edge cases, improve coverage, or test a specific function for any AWS Python project.
AWS Unit Testing Skill
Generate unit tests that cover every branch, boundary, and edge case in
business logic by reading the actual source code.
Core Principle
Unit tests isolate business logic from AWS infrastructure. Mock all
external dependencies (boto3, HTTP calls, database). Test the logic only.
How to Generate Unit Tests
Phase 1: Identify Business Logic
Read the handler source and separate concerns:
Layer
What It Does
Unit Test?
Input parsing / validation
Extracts and validates fields
Yes
Business rules
Decisions, calculations, transformations
Yes
Data formatting / mapping
Converts between formats
Yes
AWS service calls
Reads/writes to S3, DynamoDB, etc.
No (integration test)
HTTP response building
Constructs status code + body
Yes
Error handling logic
Decides which error to return
Yes
Phase 2: Map Every Branch
Read the code and create a branch map. Every control flow path needs a test:
Function: process_order(event)
├── if not event.get("body") → 400 missing body [test_1]
├── try: json.loads(body)
│ └── except JSONDecodeError → 400 invalid JSON [test_2]
├── if "order_id" not in data → 400 missing order_id [test_3]
├── if "amount" not in data → 400 missing amount [test_4]
├── if amount <= 0 → 400 invalid amount [test_5]
├── if amount > 10000 → 400 exceeds limit [test_6]
├── if currency not in SUPPORTED → 400 unsupported [test_7]
├── try: save_to_db(order)
│ ├── except ConditionalCheckFailed → 409 duplicate [test_8]
│ └── except ClientError → 500 internal error [test_9]
├── if notify_customer: send_notification() [test_10]
└── return 200 success [test_11]
Phase 3: Identify Boundaries
For every numeric, string, or collection parameter, test at the boundaries:
Parameter Type
Boundary Values to Test
Integer/Float
0, 1, -1, max-1, max, max+1, MIN_INT, MAX_INT
String
"", single char, max length, max+1, unicode, whitespace-only
Idempotency: same request twice produces same result (no duplicates)
Encoding: UTF-8, base64 isBase64Encoded, mixed encodings in headers
Extra fields: unknown keys in request don't crash or get executed
Mock Strategy for Unit Tests
# GOOD: Mock at the boundary (AWS calls)with patch("mymodule.handler.boto3.client") as mock_client:
mock_client.return_value.get_item.return_value = {"Item": {"id": "123"}}
result = handler(event, ctx)
# GOOD: Mock a specific helper that makes external callswith patch("mymodule.handler.fetch_from_s3") as mock_fetch:
mock_fetch.return_value = {"data": "value"}
result = handler(event, ctx)
# BAD: Don't mock the function under test# BAD: Don't mock internal pure functions# BAD: Don't mock Python builtins (json.loads, etc.)
Commands
# Run all unit tests
pytest tests/unit/ -v -m unit
# Run with coverage
pytest tests/unit/ -v -m unit --cov=src/ --cov-report=term-missing --cov-branch
# Run a specific test class
pytest tests/unit/test_handler.py::TestBusinessRules -v
# Run with verbose failure output
pytest tests/unit/ -v -m unit --tb=long