EN
My account

Your privacy, your call. No advertising cookies. May we count your visit in aggregate (Cloudflare, no cookies) and remember where you came from? If you reject, we won’t measure your visit. · Cookies · Privacy

Privacy settings

Choose what we measure and what we keep in this browser. We never sell or share your data.

Essential

Remember your theme, language, saved items and this choice. Without them the site cannot work the way you ask.

Always on

Keeps the source of your first and latest visit for 90 days (utm parameters and referring site). It only leaves your browser if you subscribe to the newsletter.

Cloudflare Web Analytics counts visits in aggregate: page, referring site, country, browser and load times. No cookies, no identifiers and no profiling; nothing is stored in your browser. It only loads if you accept it. If you reject it or switch it off, it does not load (or stops loading from the next page) and we do not count your Telegram clicks either.

Cookies · Privacy

Work · Professional prompt

Write unit tests

Professional structure: role, context, objective, details, steps, format, criteria and self-check. Designed for better results, not guaranteed ones: always review the answer.

Never use real personal data. If you need to, run it through the data cleaner.

Fill in the blanks
## Role
Act as a software quality engineer specialising in automated testing.

## Context
I have a function with no tests and want to cover it properly.

## Objective
Generate clear unit tests that cover the expected behaviour.

## Details (fill in what is in square brackets)
- [function or module]
- [language and test framework]
- [expected behaviour]

## Step-by-step instructions
1. List the behaviours to test.
2. Add edge cases: empty, null, extreme values and odd formats.
3. Write tests whose names describe the behaviour.
4. Say which cases cannot be tested without test doubles.

## Output format
List of cases and the complete test file in a code block.

## Quality criteria
- Each test checks one thing.
- Tests do not depend on order or the network.
- It uses the stated framework.

## Self-check
Before answering, check every quality criterion. If information is missing, ask me instead of making it up, and at the end state what you have assumed.

The link opens the empty template: what you type is not included.

Objective

Generate clear unit tests that cover the expected behaviour.

When to use it

This prompt is ideal when you have stable, pure functions needing comprehensive coverage or when you are refactoring legacy code and require a safety net. It excels at uncovering hidden edge cases you might have overlooked. However, it is less effective for complex integration scenarios involving external APIs, databases, or UI interactions, where mock objects and dependency injection become messy. Avoid relying on this for highly coupled, monolithic code; you should refactor those into smaller, testable units first for better results.

Worked example: input (fictional data)

[function or module]: function calculateSubscriptionDiscount(price, userTier, loyaltyYears) { if (price < 0) return 0; let discount = 0; if (userTier === 'premium') discount = 0.2; else if (userTier === 'gold') discount = 0.1; if (loyaltyYears > 5) discount += 0.05; return price * (1 - discount); } [language and test framework]: JavaScript with Jest [expected behaviour]: Calculate the final price after applying tier-based discounts and a loyalty bonus for customers over five years. Premium users get 20% off, gold get 10%. Loyalty bonus adds 5% on top.

Worked example: full response

List of cases to test: - Price is zero: should return zero. - Price is negative: should return zero. - Standard user, no loyalty: no discount applied. - Gold user, < 5 years: 10% discount applied. - Premium user, < 5 years: 20% discount applied. - Gold user, 6 years: 15% discount applied. - Premium user, 6 years: 25% discount applied. Test file: describe('calculateSubscriptionDiscount', () => { test('returns 0 for zero price', () => { expect(calculateSubscriptionDiscount(0, 'standard', 0)).toBe(0); }); test('returns 0 for negative price', () => { expect(calculateSubscriptionDiscount(-100, 'standard', 0)).toBe(0); }); test('applies no discount for standard user', () => { expect(calculateSubscriptionDiscount(100, 'standard', 1)).toBe(100); }); test('applies 10% for gold user', () => { expect(calculateSubscriptionDiscount(100, 'gold', 1)).toBe(90); }); test('applies 20% for premium user', () => { expect(calculateSubscriptionDiscount(100, 'premium', 1)).toBe(80); }); test('adds 5% loyalty bonus for gold user', () => { expect(calculateSubscriptionDiscount(100, 'gold', 6)).toBe(85); }); test('adds 5% loyalty bonus for premium user', () => { expect(calculateSubscriptionDiscount(100, 'premium', 6)).toBe(75); }); });

Variants

Quick smoke tests

Focus only on the happy path and two critical edge cases. Provide a concise summary of the test logic rather than a full file. This is best for rapid prototyping when you need a quick sanity check before committing your code, ensuring core functionality holds up without writing an exhaustive suite.

TDD for beginners

Explain each test case in plain English before writing the code. Break down the logic so it is easy to understand for a junior developer. Focus on readability and standard naming conventions, ensuring the output serves as a learning tool for understanding how to structure tests effectively.

Security-focused testing

Prioritise tests that check for invalid inputs, boundary conditions, and potential type coercion errors. Include tests that attempt to inject unexpected data types to ensure the function fails gracefully. This approach is essential for public-facing modules where input sanitisation and robust error handling are critical for application stability.

Common mistakes

Related guide

General and assistant-specific tips

Tips by assistant

  • Claude: ask for the result as an artifact to view and edit it separately from the chat.

Getting the most out of it

  • Paste the prompt as is and only replace what is in [brackets].
  • If the answer does not fit, do not start over: ask for “shorter”, “more formal” or “as a table”.
  • Always review the result before using it: AI can get facts, dates or names wrong.

Before you paste it: quick checklist

  • Remove client names, amounts and internal data before pasting.
  • Say who the text is for and which tone you want.
  • Ask for a specific length: “120 words max” or “three bullet points”.
  • Read the result aloud and fix anything you wouldn’t say yourself.

How to adapt it to your assistant

The template works the same in ChatGPT, Gemini, Copilot or Claude because it only uses plain language. If your assistant supports fixed instructions (custom instructions, Gems or projects), you can store your preferred tone and format there and paste only the variable part. On a free plan, split long requests into two or three shorter messages.

See all Work prompts

More professional prompts

← All prompts