Generate Tests
# Prompt: Generate Tests (Pest)
Generate tests for Laravel features using **Pest** syntax.
---
## Context
- Testing rules: @.cursor/rules/testing-rules.mdc
- Business rules: @docs/business-rules.md
- Example tests: @examples/laravel/ProductServiceTest.php
Stack: Laravel 11+, Pest 3+, `RefreshDatabase` for feature tests.
## Target
**Class / endpoint under test:**
`CLASS_OR_ROUTE`
**Type:** `unit` | `feature` | `both`
**Business rules to cover:**
`BR-001, BR-002, ...`
**Files to test (attach with @):**
- `@app/Services/ProductService.php`
- `@app/Http/Controllers/Api/ProductController.php`
## Requirements
### Unit tests (service)
- Mock `ProductRepositoryInterface` with Mockery
- No database
- Cover happy path + each failure rule
- Use `describe()` and `it()` with readable names
### Feature tests (HTTP)
- Use `RefreshDatabase`
- Use model factories
- Assert status, JSON structure, and key fields
- Test validation failures (422) and conflicts (409)
## Output
- Full Pest test file(s) with correct namespaces and `uses()` if needed
- Table mapping **Rule ID → test name**
## Do not
- Test Laravel framework internals
- Depend on fixed database IDs
- Leave empty `it()` blocks
---
## Example (filled)
**Target:** `ProductService::create`
**Type:** unit
**Rules:** BR-001, BR-002, BR-003
**Task:** Create `tests/Unit/Services/ProductServiceTest.php` with:
1. Creates product when data is valid
2. Throws `DuplicateSkuException` when SKU exists
3. Throws `InvalidProductPriceException` when price is negative
Provide Mockery setup for repository in `beforeEach`.
---
## Feature test snippet referencewhen to use it
Community prompt sourced from the open-source GitHub repo YoungC0DE/cursor-ai-template (MIT). A "Generate Tests" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.
tags
roleplaycommunitygeneral
source
YoungC0DE/cursor-ai-template · MIT