DeepSeek Unit Test Generator Prompt
You are a senior software engineer specialising in TDD with expertise in tests that catch production bugs.
Category
💻 Coding
Difficulty
Intermediate
Models
3
Last Updated
2026-06-28
Works with
📄 Example output
⚠️ Common Mistakes
❓ FAQ
⚙️ Fill in your variables
📋 Prompt
You are a senior software engineer specialising in TDD with expertise in tests that catch production bugs.
Function/module: [function to test]
Language: [programming language]
Framework: [testing framework — Jest/pytest/JUnit/Go test]
Edge cases: [edge cases to cover]
Paste the code:
[code]
Task: Write comprehensive unit tests:
1. HAPPY PATH TESTS: Normal use cases that should succeed
2. EDGE CASE TESTS: Empty inputs, null/undefined, boundary values, type mismatches
3. ERROR CASE TESTS: What should throw or return error
4. MOCKING: External dependencies that need mocking
5. COVERAGE REPORT: Estimated % coverage with explanation
6. GAPS: What you couldn't test and why
Format: Complete test file, ready to run. Inline comments explaining non-obvious test logic.
Function/module: [function to test]
Language: [programming language]
Framework: [testing framework — Jest/pytest/JUnit/Go test]
Edge cases: [edge cases to cover]
Paste the code:
[code]
Task: Write comprehensive unit tests:
1. HAPPY PATH TESTS: Normal use cases that should succeed
2. EDGE CASE TESTS: Empty inputs, null/undefined, boundary values, type mismatches
3. ERROR CASE TESTS: What should throw or return error
4. MOCKING: External dependencies that need mocking
5. COVERAGE REPORT: Estimated % coverage with explanation
6. GAPS: What you couldn't test and why
Format: Complete test file, ready to run. Inline comments explaining non-obvious test logic.
// calculateMonthlyPayment.test.js
import { calculateMonthlyPayment } from './mortgageCalculator';
describe('calculateMonthlyPayment', () => {
// Happy path
it('calculates correct payment for standard mortgage', () => {
// £200K loan, 4% annual, 25 years
expect(calculateMonthlyPayment(200000, 4, 25)).toBeCloseTo(1055.68, 2);
});
it('handles 0% interest (interest-free loan = principal ÷ months)', () => {
expect(calculateMonthlyPayment(120000, 0, 10)).toBeCloseTo(1000, 2);
});
// Edge cases
it('throws RangeError for zero or negative principal', () => {
expect(() => calculateMonthlyPayment(0, 4, 25)).toThrow(RangeError);
expect(() => calculateMonthlyPayment(-5000, 4, 25)).toThrow(RangeError);
});
it('throws TypeError for string inputs', () => {
expect(() => calculateMonthlyPayment('200000', 4, 25)).toThrow(TypeError);
});
it('handles extreme interest rate without NaN or Infinity', () => {
const result = calculateMonthlyPayment(10000, 50, 1);
expect(result).not.toBeNaN();
expect(result).not.toBe(Infinity);
expect(result).toBeGreaterThan(10000);
});
// Precision
it('rounds to 2 decimal places (pence)', () => {
const result = calculateMonthlyPayment(150000, 3.75, 20);
const decimals = result.toString().split('.')[1]?.length ?? 0;
expect(decimals).toBeLessThanOrEqual(2);
});
});
// Coverage: ~85% — gaps: concurrent calls (pure function, N/A)
import { calculateMonthlyPayment } from './mortgageCalculator';
describe('calculateMonthlyPayment', () => {
// Happy path
it('calculates correct payment for standard mortgage', () => {
// £200K loan, 4% annual, 25 years
expect(calculateMonthlyPayment(200000, 4, 25)).toBeCloseTo(1055.68, 2);
});
it('handles 0% interest (interest-free loan = principal ÷ months)', () => {
expect(calculateMonthlyPayment(120000, 0, 10)).toBeCloseTo(1000, 2);
});
// Edge cases
it('throws RangeError for zero or negative principal', () => {
expect(() => calculateMonthlyPayment(0, 4, 25)).toThrow(RangeError);
expect(() => calculateMonthlyPayment(-5000, 4, 25)).toThrow(RangeError);
});
it('throws TypeError for string inputs', () => {
expect(() => calculateMonthlyPayment('200000', 4, 25)).toThrow(TypeError);
});
it('handles extreme interest rate without NaN or Infinity', () => {
const result = calculateMonthlyPayment(10000, 50, 1);
expect(result).not.toBeNaN();
expect(result).not.toBe(Infinity);
expect(result).toBeGreaterThan(10000);
});
// Precision
it('rounds to 2 decimal places (pence)', () => {
const result = calculateMonthlyPayment(150000, 3.75, 20);
const decimals = result.toString().split('.')[1]?.length ?? 0;
expect(decimals).toBeLessThanOrEqual(2);
});
});
// Coverage: ~85% — gaps: concurrent calls (pure function, N/A)
🏆
💡 Pro Tips
Best model for this prompt
DeepSeek
DeepSeek V3 / R1
Write test names as full sentences — 'returns null when user not found' beats 'test null'
Tests must be isolated — run alone, in any order, same result every time
Mock Date.now() in time-dependent functions — otherwise tests break at midnight
Test behaviour, not implementation — after refactoring, tests should pass unchanged
Testing private methods instead of public behaviour — breaks on every refactor
Tests with no assertions — always pass, catch nothing
Overly complex setup — if you need 50 lines of setup, the function under test does too much
Not testing error paths — most production bugs live in the code that handles errors
- How much test coverage should I aim for?80–90% is reasonable. 100% often produces low-value tests written to hit a number. Focus on critical paths, error cases, and edge cases — not percentages.
- Should I use TDD?TDD produces better-designed, more testable code and catches design flaws early. Many teams use a hybrid: TDD for complex logic, tests-after for straightforward CRUD.
- What's the testing pyramid?Many unit tests (fast, isolated), some integration tests (components working together), few e2e tests (full user journeys). Most suites invert this pyramid accidentally, creating slow, brittle test suites.
- Is DeepSeek good for writing tests?Yes — DeepSeek R1 reasons through edge cases systematically before writing each test. Always review generated tests for logic accuracy before trusting them.