Testing
Writing tests
As a test runner we use minimalistic eftest
runner. It's very close to clojure.test
but has a few improvements for showing the results in a more readable way.
There is a pre-configured testing coverage using cloverage/cloverage
. The coverage report is generated in target/coverage
directory.
You can run them with the following command:
Integration tests
test/myproject/test_utils.clj
contains a few utility functions that are used in the tests for managing CSRF-token and cookies, and for cleaning up the database between tests.
For integration tests we start the system using existing fixture from integrant-extras
library:
Then in your tests you can have an access the system components via reitit-extras.tests/*test-system*
dynamic variable. It contains the system map with all the components started with the :test
profile.
The real server and database are started, so you can test the whole stack. The database is cleaned up between tests using myproject.test-utils/with-truncated-tables
fixture.
For testing some UI parts we have org.clj-commons/hickory
library that parses HTML and provides a nice API for querying the DOM.
Tip
Database
The database is cleaned up between tests using myproject.test-utils/with-truncated-tables
fixture. It deletes data from all the tables except migrations in the database before each test.
For SQLite the database is stored in the memory, so it is created from scratch for each test namespace.
For PostgreSQL the database is created using Testcontainers library with JDBC support and TC_DAEMON=true
mode - it allows to reuse the database between tests.
The database is running till JVM is shutdown.