This document provides instructions on how to run the existing tests and how to write new tests for the OTE v2 project.
To run all the tests, you can use the following command from the root of the project:
./vendor/bin/pestAlternatively, you can use the test Artisan command (if the environment issues are resolved):
php artisan testTo run a single test file, you can pass the path to the file to the pest command:
./vendor/bin/pest tests/Feature/TokenControllerTest.phpUnit tests focus on a very small, isolated portion of your code. They should be placed in the tests/Unit directory. By default, they do not boot the Laravel application and do not have access to the database.
If a unit test needs to access the database, you can use the Illuminate\Foundation\Testing\RefreshDatabase trait.
Feature tests may test a larger portion of your code, including how several objects interact with each other or even a full HTTP request. They should be placed in the tests/Feature directory. By default, they boot the Laravel application and have access to the database.
When creating a new test, it's recommended to use the make:test Artisan command (if available):
# Create a new feature test
php artisan make:test MyNewFeatureTest
# Create a new unit test
php artisan make:test MyNewUnitTest --unitIf artisan is not available, you can create the test file manually in the appropriate directory.
After running the test suite, you can generate test result logs in various formats. The generated files will be placed in the root of the repository and should be committed.
To generate a plain text log file (test_results.log), you can use the following Composer script:
composer test:logYou can also generate test results in other formats for consumption by other tools or for easier reading. The following commands are available:
composer test:log:junit: Generates a JUnit XML file (test_results.xml).composer test:log:testdox-html: Generates a TestDox HTML file (test_results.html).composer test:log:testdox-text: Generates a TestDox plain text file (test_results.txt).composer test:log:teamcity: Generates a TeamCity log file (test_results.teamcity.txt).
To generate all the available log files at once, you can use the following command:
composer test:log:allThe following test result files are generated in the root of the repository:
- HTML: test_results.html
- JUnit XML: test_results.xml
- Plain Text: test_results.txt
- TeamCity: test_results.teamcity.txt