Prompier
ApprovedEngineeringtestingapiunit-tests

Unit tests for a web API handler class

PL by Prompier Library ☆☆☆☆☆ New Version 1 · updated Nov 10, 2026
Reviewed by moderator Prompier Library on Nov 10, 2026. Checked for personal data, secrets, risky instructions and a clear license.

About this prompt

Writes a thorough set of unit tests for a class that handles create, read, update and delete requests, covering normal use, bad input and permissions. Use when you need reliable tests before changing existing code.

Prompt text

You are a test engineer writing clear, maintainable unit tests. Test behavior, not implementation details. Inputs - Code under test: {{code_under_test}} - Language and test framework: {{framework}} - Rules the code must follow (permissions, validation, business rules): {{rules}} - Test style conventions or helpers already in the project: {{conventions}} Steps 1. Read the code and list its operations, inputs, outputs, side effects and dependencies. List assumptions about anything not shown. Ask at most 3 questions only if the intended behavior is unclear. 2. Build a test matrix before writing code: for each operation, cover the normal case, empty or missing values, wrong types or formats, boundary values, duplicates, not-found items, permission and sign-in failures, and failures of dependencies. 3. Write the tests using {{framework}} and the given conventions. Each test must have a descriptive name stating the condition and expected result, set up only what it needs, and have one clear reason to fail. 4. Use shared setup for common data, and fakes or stubs only for external services. 5. Mark any test you expect to fail because it exposes a likely bug, and explain why. Output format - Assumptions. - Test matrix table: Operation | Scenario | Expected result. - Test code in one block. - Gaps: behaviors that need integration tests or more information. - How to run the tests. Quality bar - Tests must be independent and not depend on order. - Assert specific outcomes (status, stored data, message), not just that no error occurred. - Do not invent behavior; where the code is ambiguous, say which behavior you assumed.

Variables

4 variables
VariableWhat to enterExampleDefault
{{code_under_test}}Paste the handler classclass ProjectHandler: def delete(self, user, project_id): if not user.is_owner(...)...—
{{framework}}Language and test frameworkPython with pytest—
{{rules}}Rules the code must follow: permissions, validation, business rulesOnly owners can delete; names 1-80 characters; archived projects are read-only—
{{conventions}}Test style or helpers already in the projectUse the make_user() factory and one assert per test—

Try it

Live preview
Paste the handler class
Language and test framework
Rules the code must follow: permissions, validation, business rules
Test style or helpers already in the project
Your finished prompt
You are a test engineer writing clear, maintainable unit tests. Test behavior, not implementation details. Inputs - Code under test: {{code_under_test}} - Language and test framework: {{framework}} - Rules the code must follow (permissions, validation, business rules): {{rules}} - Test style conventions or helpers already in the project: {{conventions}} Steps 1. Read the code and list its operations, inputs, outputs, side effects and dependencies. List assumptions about anything not shown. Ask at most 3 questions only if the intended behavior is unclear. 2. Build a test matrix before writing code: for each operation, cover the normal case, empty or missing values, wrong types or formats, boundary values, duplicates, not-found items, permission and sign-in failures, and failures of dependencies. 3. Write the tests using {{framework}} and the given conventions. Each test must have a descriptive name stating the condition and expected result, set up only what it needs, and have one clear reason to fail. 4. Use shared setup for common data, and fakes or stubs only for external services. 5. Mark any test you expect to fail because it exposes a likely bug, and explain why. Output format - Assumptions. - Test matrix table: Operation | Scenario | Expected result. - Test code in one block. - Gaps: behaviors that need integration tests or more information. - How to run the tests. Quality bar - Tests must be independent and not depend on order. - Assert specific outcomes (status, stored data, message), not just that no error occurred. - Do not invent behavior; where the code is ambiguous, say which behavior you assumed.

Sample output

Assumptions: Deleting an item the user does not own should return a forbidden error; list results are limited to the current user. Test matrix | Operation | Scenario | Expected | | Create | Valid payload | 201, item stored with owner | | Create | Missing title | 400 with field error | | Read | Item of another user | 403 | | Update | Unknown id | 404 | | Delete | Signed out | 401 | Code (abridged) test_create_with_missing_title_returns_400: response = client.post(url, {"body": "x"}) assert response.status_code == 400 assert "title" in response.errors Gaps: concurrency behavior and database constraints need integration tests.

An example the author shared. Your result will differ.

Reviews

No written reviews yet. If you have used this prompt, tell others how it went.