Skip to content

Testing ✔

Splines edited this page Jul 1, 2024 · 18 revisions

Unit tests

testing in vscode

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).

Troubleshooting

  • In VSCode, open the Output pane and choose Ruby 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 the test environment and it should work again.

Code coverage

We use Codecov to track our code coverage. See the dashboard here.


Cypress frontend tests

We use Cypress as frontend Javascript testing framework. The cypress tests can be found in the spec/cypress/ folder. They will also run in our pipeline via GitHub Actions. To run them locally, use the following command inside the docker/test/ folder:

docker compose -f docker-compose.yml -f cypress.yml -f cypress-interactive.yml up --exit-code-from cypress

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.


Test writing conventions

Clone this wiki locally