Use these checklists to ensure you’re testing the correct things for each type of code change.
Permissions.
Users without the necessary role or permissions get a 403 response.
Users with the necessary permissions get a 200 response.
Validations
For each required parameter, requests without it get an error response.
For each parameter with other kinds of validations, requests with invalid values get an error response.
A request with all required parameters having valid values gets a 200 response.
Events
For valid requests, the expected event(s) are triggered. Only test that the event is triggered (via Event::assertDispatched
or similar), do not test that the side effects of the event have occurred.
Data changes
For valid requests, the expected data changes are made.
Response messages
Test the value of response messages in different scenarios. Use these tests only when copy of message is extremely important.
For each listener, use Event::assertListening
to ensure it is attached to the event.
Listeners:
Manually create the event and listener objects then call handle
on the listener. Then, test that the expected behavior in the listener occurs.
https://kirschbaumdevelopment.com/insights/structuring-and-testing-your-laravel-events-and-listeners