Skip to content

Testing

How to Write and Run Unit Tests

A test is not a unit test if:

  • It talks to the database
  • It communicates across the network
  • It touches the file system
  • It can’t run at the same time as any of your other unit tests
  • You have to do special things to your environment (such as editing config files) to run it

Unit tests live in the src/test folder of our sbt projects.

Run all unit tests from terminal:

sbt test

How to Write and Run Integration Tests

Mostly you should consider writing unit tests. These can be executed fast and help developers more in their daily work.

You might need to create an integration test because:

  • The test needs to talk to a database
  • It requires network
  • It is slow and cannot run in parallel with other tests
  • You have to do special things to the environment in order to run it

In this case create it in the modules/test-it/src/test/scala/ directory.

Run all integration tests from the terminal.

make test-it

Run all end-to-end HTTP API tests from the terminal.

make test-e2e

Sipi Image Versioning

Integration tests use different Sipi image versions based on environment:

  • Local development: Uses daschswiss/knora-sipi:latest (default)
  • CI environment: Uses exact git version (e.g., v31.20.0-6-gfa52f5f)

You can override this behavior with environment variables:

  • SIPI_VERSION=<version> - Use specific version
  • SIPI_USE_EXACT_VERSION=true - Force exact git version locally

If the required image doesn't exist locally, build it with:

make docker-build-sipi-image

Debugging

You can debug unit tests directly in your IDE.

For debugging integration tests locally with sbt or your IDE, tests will use the latest Sipi image by default. If you need a specific version, use the environment variables described above.