-
Notifications
You must be signed in to change notification settings - Fork 10
Testing ✔
In VSCode, you can install the recommended extension "Ruby Test Explorer". You must also have a recent version of python installed (at least Python3.8). Then go to tests and click on Run all tests
. See the "Output" tab in VSCode for errors of the plugin. You can also go to a _spec.rb
file and run tests from there individually.
Note that in the test explorer pane, you should prefer to use Run all tests
instead of "Run tests" for the "models". This is because with "Run all tests" only one docker container will be created while for the latter, a new docker container is created for every new _spec.rb
file. The creation of the docker container takes quite some time, so use Run all tests
to get faster test results (really a lot faster, like ~15min vs. ~1min).
In other IDEs, use respective test extensions. From the shell you can invoke the tests using TODO (include just
command).
- RSpec style guidelines (especially for naming)
- In VSCode, open the
Output
pane and chooseRuby Test Explorer Log
to see the output of the extension. This is the place where you might find error messages, e.g. if no tests are shown in the test explorer. - One possible hickup might be a lost connection to the database. In this case, simply restart the
db
docker container in thetest
environment and it should work again.
We use Codecov to track our code coverage. See the dashboard here.
We use Cypress as frontend Javascript testing framework. The cypress tests can be found in the spec/cypress/e2e/
folder. They will also run in our pipeline via GitHub Actions. To run them locally, use the following command:
just test cypress
Wait a few seconds for the Cypress test runner UI to show up (we're waiting for the MaMpf container to come online). Whenever you close this window, the Docker containers will automatically stop.
If you're using WSL, make sure to have an up-to-date version wsl --update
(the latest version includes an X11 server by means of WSLg). After running the above command, a window should open up with the Cypress test runner UI. This window is GUI-forwarded from the Linux WSL system to your Windows system.
Note that cypress shares the test database with the Rails unit tests. This shouldn't be a problem as they both clean the whole database before they execute anything. But this means, we shouldn't run cypress and unit tests at the same time.
- A must! Learn about the Cypress fundamentals in this interactive guide by Cypress.
- Cypress starting guide
- Cypress best practices
- Cypress assertions list (for reference)
- Please also read this section about retriability to learn that you should not chain of actions, e.g.
click()
. This is especially important to avoid writing flaky tests. - How can I wait for my XHR requests to be complete? See the last paragraph in this section. I.e. use
intercept()
in combination withwait()
. - Use
it.only()
if you only want that test to be run. You might also want to useit.skip()
. Also works withdescribe.only()
ordescribe.skip()
. -
Custom commands: Make sure to look into the
spec/cypress/support/commands.js
file where we have added many useful commands to use in your Cypress tests, e.g.cy.getBySelector("your-selector")
, instead of having to writecy.get("[data-cy='your-selector']")
all the time.