snipe-it/TESTING.md

66 lines
1.9 KiB
Markdown
Raw Normal View History

2023-03-08 11:58:36 -08:00
# Running the Test Suite
2023-03-08 11:58:36 -08:00
This document is targeted at developers looking to make modifications to this application's code base and want to run the existing test suite.
2023-03-08 11:58:36 -08:00
Before starting, follow the [instructions](README.md#installation) for installing the application locally and ensure you can load it in a browser properly.
2023-03-08 11:58:36 -08:00
## Unit and Feature Tests
2023-03-08 11:58:36 -08:00
Before attempting to run the test suite copy the example environment file for tests and update the values to match your environment:
2023-03-08 11:58:36 -08:00
`cp .env.testing.example .env.testing`
2023-08-30 11:27:26 -07:00
The following should work for running tests in memory with sqlite:
```
# --------------------------------------------
# REQUIRED: BASIC APP SETTINGS
# --------------------------------------------
APP_ENV=testing
APP_DEBUG=true
APP_KEY=base64:glJpcM7BYwWiBggp3SQ/+NlRkqsBQMaGEOjemXqJzOU=
APP_URL=http://localhost:8000
APP_TIMEZONE='UTC'
APP_LOCALE=en-US
2023-08-30 11:27:26 -07:00
# --------------------------------------------
# REQUIRED: DATABASE SETTINGS
# --------------------------------------------
DB_CONNECTION=sqlite_testing
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=null
#DB_USERNAME=null
#DB_PASSWORD=null
```
To use MySQL you should update the `DB_` variables to match your local test database:
```
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE={}
DB_USERNAME={}
DB_PASSWORD={}
```
2023-03-08 11:58:36 -08:00
Now you are ready to run the entire test suite from your terminal:
2024-02-12 12:28:27 -08:00
```shell
php artisan test
````
2023-03-08 11:58:36 -08:00
To run individual test files, you can pass the path to the test that you want to run:
2024-02-12 12:28:27 -08:00
```shell
php artisan test tests/Unit/AccessoryTest.php
```
Some tests, like ones concerning LDAP, are marked with the `@group` annotation. Those groups can be run, or excluded, using the `--group` or `--exclude-group` flags:
```shell
php artisan test --group=ldap
php artisan test --exclude-group=ldap
```
This can be helpful if a set of tests are failing because you don't have an extension, like LDAP, installed.