---
title: "Tests"
canonical_url: "https://handbook.propay.co.za/laravel/tests"
---
# Tests

We recommend using the [Pest](https://pestphp.com/) testing suite instead of PHPUnit to write tests for your applications. We have found that Pest organizes your tests, datasets, etc. in a much better way.

You can run the tests in a couple of different ways: `./vendor/bin/pest`, or `php artisan test` built into Laravel. Our tests are run on each pull request to a package.

## Feature

Feature tests may test a larger portion of your code, including how several objects interact with each other or even a full HTTP request to a JSON endpoint. Generally, most of your tests should be feature tests. These types of tests provide the most confidence that your system as a whole is functioning as intended.

## Unit

Unit tests are tests that focus on a very small, isolated portion of your code. In fact, most unit tests probably focus on a single method. Tests within your "Unit" test directory do not boot your Laravel application and therefore are unable to access your application's database or other framework services.

## Benefits

There are some great benefits to writing tests:

- Fewer bugs.
- Happier customers.
- Happier employers.
- Confident developers. You won’t fear breaking something when coming back to the project after a while.
- New hires can be productive from day one, especially if you follow Laravel’s guidelines. Changed some code? No problem. Just run `php artisan test`, see what you broke, fix it, and repeat!

> Being able to make a project immensely more stable thanks to automated testing will do wonders for your career.

## How To

Copy the `.env` file to `.env.testing` file and this environment file will be used when you run your tests. Remember to add values to the `.env.testing` file for your local setup.

Some guidelines when setting up testing for a project:

- Lazily refresh your database before each test
- Make use of factories to help you with fake data and tests
- Test against the production stack whenever it’s possible
- Use database transactions to rollback changes after each test
- Don’t waste API calls, use mocks
- Prevent stray HTTP requests to identify slow tests

Tutorial:

Laracasts has a great free testing course on [Pest](https://laracasts.com/topics/pest) that you can use to upskill.


## Sitemap

See the full [sitemap](https://handbook.propay.co.za/sitemap.md) for all pages.
