Skip to main content

Copilot Prompt to Generate Unit Tests from Specs

Turn user stories and acceptance criteria into thorough test suites covering happy paths, edge cases, error scenarios, and data integrity checks.

Füllen Sie die Platzhalter aus

Edit the values, then copy your finished prompt.

Ihr Prompt
prompt.txt

                                

What this prompt does

This prompt makes the AI a senior QA engineer that converts a feature spec into a comprehensive test suite. You provide the [acceptance_criteria], the [language], the [test_framework], the [class_under_test], and the [dependencies] to mock, and it generates tests across five categories: happy path, edge cases, error scenarios, data integrity, and the fixtures and factories to support them. The output is a complete, ready-to-run test file rather than scattered snippets.

The structure works because it pushes past the happy path that most developers stop at. Each acceptance criterion gets a happy-path test with a descriptive test_action_when_condition_should_result name and an Arrange-Act-Assert layout. The edge-case category forces null and empty inputs, boundary values, Unicode, and collection extremes. The error category asks what happens when each dependency fails, and [additional_test_concern] lets you pin a specific worry. Test data is built with your [factory_approach], and the rules ban magic numbers and demand real assertions instead of "no exception thrown."

When to use it

  • You have acceptance criteria and want a real suite, not just happy-path coverage
  • You keep skipping edge cases under deadline and want them generated for you
  • You need every external [dependencies] mocked so tests never hit real APIs
  • You want descriptive test names that double as documentation
  • You need data-integrity checks like idempotency and cascade effects
  • You want fixtures and factories scaffolded with your project's [factory_approach]

Example output

You get a single ready-to-run test file in [test_framework], organized into the five categories with clear AAA sections and comments explaining why each edge case matters. Tests use framework-native assertions, mock every dependency you listed, and rely on [factory_approach] for setup and teardown, with parameterized data providers where they reduce duplication.

Pro tips

  • Write [acceptance_criteria] as concrete, testable statements; vague specs produce vague tests
  • Name [class_under_test] with its full path so the generated test targets the right unit
  • List every external [dependencies] so nothing accidentally calls a real API or database
  • Set [factory_approach] to your project's real tool (Laravel factories) so setup matches your conventions
  • Use [additional_test_concern] for the integrity check you care about, like tokens being hashed not stored plain
  • Run the suite; descriptive names and real assertions are the goal, but AI tests can still assert the wrong thing

Frequently Asked Questions

Does it just test the happy path?
No. It generates five categories: happy path, edge cases, error scenarios, data integrity, and fixtures. The edge-case and error categories specifically cover null inputs, boundary values, Unicode, and what happens when each mocked dependency fails.
Will the tests call real external services?
No. A code-quality rule requires mocking external services and never calling real APIs. You list the services in the `[dependencies]` variable, and the generated tests mock each one so the suite stays fast and deterministic.
What does it use for test data?
Whatever you set in the `[factory_approach]` variable, such as Laravel model factories. It creates the necessary fixtures plus setup and teardown methods, and uses shared fixtures for related tests to reduce duplication.
Are the test names readable?
Yes. The prompt enforces descriptive names in the format test_action_when_condition_should_result, so each test reads like documentation of the behavior it verifies, which makes failures far easier to diagnose.
Can I trust the generated assertions?
Treat them as a strong starting point. The rules demand real framework-native assertions rather than just checking that no exception was thrown, but you should run the suite, since AI-generated tests can occasionally assert the wrong expected value.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Mehr in AI Coding Assistants

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support