4 changed files with 76 additions and 37 deletions
@ -0,0 +1,31 @@
|
||||
--- |
||||
nav_order: 2 |
||||
--- |
||||
|
||||
# Testing best practice |
||||
|
||||
Note many old tests on CORE don't follow these guidelines. Feel free to bring them up to code. |
||||
|
||||
## CollectionTimeHelper |
||||
|
||||
Very useful class containing lots of date helper methods. Overuse these. |
||||
|
||||
## Year-specific tests |
||||
|
||||
The following guidelines should create tests that are: |
||||
|
||||
- Unlikely to break between years |
||||
- Clearly marked when year specific |
||||
- Test up to date code wherever possible |
||||
|
||||
Note that guidelines are directed for the point in time after a new form build has been completed. |
||||
|
||||
If you're currently in new form build and writing new tests, imagine that it is currently post release of the form and follow the guidance from there. This is so we can be happy tests will not break on release day as well. |
||||
|
||||
- If writing a test that doesn't need to be year specific, use `current_collection_start_year` or `current_collection_start_date`. |
||||
|
||||
- If writing a test for the past, use `collection_start_date_for_year(year)`, and mark the test with metadata: `{ year: xx }`. |
||||
|
||||
- If writing a test for the present & future, use `collection_start_date_for_year_or_later(year)`, and mark the test with metadata: `{ year: xx }`. |
||||
|
||||
We only maintain tests for years that are currently editable in CORE (usually this and last collection year). If you see a file that contains tests for years older, consider updating or removing them. |
||||
@ -0,0 +1,34 @@
|
||||
--- |
||||
has_children: true |
||||
nav_order: 4 |
||||
--- |
||||
|
||||
# Overview |
||||
|
||||
- We use [RSpec](https://rspec.info/) and [Capybara](https://teamcapybara.github.io/capybara/) |
||||
|
||||
- Capybara is used for our feature tests. These use the Rack driver by default (faster) or the Gecko driver (installation required) when the `js: true` option is passed for a test. |
||||
|
||||
- Capybara is configured to run in headless mode but this can be toggled by commenting out `app/spec/rails_helper.rb#L14` |
||||
|
||||
- Capybara is configured to use Gecko driver for JavaScript tests as Chrome is more commonly used and so naturally more likely to be better tested but this can be switched to Chrome driver by changing `app/spec/rails_helper.rb#L13` |
||||
|
||||
- Feature specs are generally written sparingly as they’re also the slowest, where possible a request spec is preferred as this still tests a large surface area (route, controller, model, view) without the performance impact. They are not suitable for tests that need to run JavaScript or test that a specific set of interaction events that trigger a specific set of requests (with high confidence). |
||||
|
||||
- Test data is created with [FactoryBot](https://github.com/thoughtbot/factory_bot) where ever possible |
||||
|
||||
# Parallel testing |
||||
|
||||
- The RSpec test suite can be ran in parallel in local development for quicker turnaround times |
||||
|
||||
- Setup with the following: |
||||
|
||||
```sh |
||||
bundle exec rake parallel:setup |
||||
``` |
||||
|
||||
- Run with: |
||||
|
||||
```sh |
||||
RAILS_ENV=test bundle exec rake parallel:spec |
||||
``` |
||||
Loading…
Reference in new issue