Prompt to write unit tests with ChatGPT

Coding and ITFree prompt

Paste a function and name your framework: the AI lists the cases to test, then writes readable unit tests, including the edge cases people often forget.

Customise the prompt

Your prompt

🔒 The fields stay in your browser. The prompt is only sent to the AI service you choose to open.

How do I write unit tests with ChatGPT?

Paste the function, state the language, the test framework and the expected business rules, then ask for a list of cases (normal, edge, errors) first, before the test code. The free Lunyce prompt follows this method; check that each expected result matches the rule, not just the code.

How to use it

  1. Enter the language and the test framework used in your project.
  2. Paste the function and describe in one sentence the rules it must follow.
  3. Copy or open the prompt, then run the tests: a failing test may reveal a real bug.

Tips for better results

  • Read the list of cases before the code: that is where you will spot a gap in the rules.
  • Ask "add tests for the error cases" if the coverage seems thin.
Are tests written by AI enough?

They save a lot of time, but the AI only knows what you give it. Check that the expected results match the business rules, not just the current code, which may itself be wrong.