ClaudeChatGPTCopilotDeveloper & CodeIntermediate
Unit Test Writing Framework
Write comprehensive unit tests using AAA pattern (Arrange, Act, Assert) with edge cases, mocks, and coverage targets.
Updated June 2026
When to Use
When implementing tests for the first time in a project
To standardize how the team writes tests
When test coverage is low or tests are fragile
Before refactoring critical code
How to Use This Prompt
1
Copy the prompt below into Claude or ChatGPT
2
Paste the function or module you want to test
3
Receive the complete tests with explanations
4
Implement and run in your test runner
Example Input
Language: TypeScript Framework: Jest Code: Function calculateDiscount(price, couponCode, userTier) - Applies discount based on coupon + user tier - Premium = 10% extra, VIP = 20% extra - Coupon can be percentage or fixed value - Minimum final price is R$1.00
Expected Output
describe('calculateDiscount', () => {
describe('without coupon', () => {
it('returns original price for regular user without coupon', () => {
const result = calculateDiscount(100, null, 'regular');
expect(result).toBe(100);
});
it('applies 10% discount for premium user', () => {
const result = calculateDiscount(100, null, 'premium');
expect(result).toBe(90);
});
it('applies 20% discount for VIP user', () => {
const result = calculateDiscount(100, null, 'vip');
expect(result).toBe(80);
});
});
describe('edge cases', () => {
it('never returns value less than R$1.00', () => {
const result = calculateDiscount(5, 'SAVE99', 'vip');
expect(result).toBe(1);
});
it('throws error for negative price', () => {
expect(() => calculateDiscount(-10, null, 'regular'))
.toThrow('Price must be positive');
});
});
});