Go to the root of the project and run:
composer install
- We use the file
tests/.env
to store the database credentials for the tests. - This file is specific to your environment and is not committed.
- To create one, duplicate
tests/.env.dist
and edit credentials to suit your need. - You don't have to create the mock database (default:
cruddiy_tests
), creating it is part of the tests. - If your test user does not have the privileges to create a database, just create it and fill the credentials in the
.env
. If the database exists, we will not attempt to re-create it.
Go to the root directory of the project and run vendor/bin/behat --config tests/behat/behat.yml
germain@nuc13 UCRT64 /d/Sites/cruddiy
$ vendor/bin/behat --config tests/behat/behat.yml --stop-on-failure
(...)
47 scénarios (47 succès)
449 étapes (449 succès)
0m46.61s (13.23Mb)
- Admin suite: simulate the creation of a fresh CRUD
- Public suite: impersonate a user navigating on the generated CRUD pages
- Regenarate suite: when you regenerate the CRUD pages without re-typing/checking the options (options are saved as of PR #73)
- Public After Regenerate suite: this is a duplicate of Public suite. It's here because we want to check that the CRUD pages are still OK after a regeneration.
vendor/bin/behat --config tests/behat/behat.yml --suite admin
vendor/bin/behat --config tests/behat/behat.yml --suite public
vendor/bin/behat --config tests/behat/behat.yml --suite regenerate_nogitignore
vendor/bin/behat --config tests/behat/behat.yml --suite regenerate
vendor/bin/behat --config tests/behat/behat.yml --suite public # or public_after_regenerate, it's a copy
vendor/bin/behat --config tests/behat/behat.yml tests/behat/features/admin/relations/schema.feature
You can stop the tests when the first failure arises:
vendor/bin/behat --config tests/behat/behat.yml --suite admin --stop-on-failure
Read the coverage at tests/coverage/admin.md
Update the coverage by executing:
vendor/bin/behat --config tests/behat/behat.yml --dry-run --no-snippets \
| grep -e '^Feature:' -e '^ Scenario:' \
| grep -o '^[^#]*' \
| sed 's/[[:space:]]*$//' \
| sed '/^Feature:/s/^/- /' \
| sed '/^ Scenario:/s/^/ - /' > tests/coverage.md
- For the tests we have a small structure with Products, Brands, and Suppliers
schema/Tests - Admin.sql
is the (nearly) blank structure, it is used to reset the test database every time you run the Admin test suite. It is also used to self-test the "Import Database Schema" feature.schema/Tests - Public.sql
is a dump of the test DB after the Admin test suite has been run. It cleans up the DB every time the Public test suite is run (because the suite is performing CRUD operations, which would invalidate some tests when re-run).
- To find a list of predefined assertions from the Mink extension, open
vendor\behat\mink-extension\src\Behat\MinkExtension\Context\MinkContext.php
- Test your
.feature
files individually - Then add them to the queue in
behat.yml
- Every time a test fails, a .html dump of the response is saved in
tests/behat/logs
. - You can open the files in your browser to view the state of the application when the test ran, including PHP error messages and exceptions.
- The logs directory is deleted every time a new batch of tests is ran.
- The name of the log file mimics the Behat files in the
features/
directory, eg.:- Step fails in tests\behat\features\admin\relations\schema.feature line 16
- Name of the log file: admin_relations_schema-16.html
- There is also a custom step definition Then I log the content of the page that will log a page even if there is no error
All developers are encouraged to write tests as they contribute to the project, it's easy and fun! And satisfactory!
- Read about the Gherkin syntax
- More tips
- Generate .feature files by recording your actions with the Nimbal User Journey Chrome extension