Skip to content
Tom Herold edited this page Sep 28, 2017 · 32 revisions

Testing

webKnossos support both unit tests and integration/end-to-end (E2E) tests.

Requirements

  • Google Chrome
  • node v0.12+
  • A running wK installation

Running Tests

yarn test  # For frontend unit tests
sbt test  # For E2E tests only (using a dedicated test DB)

E2E can also be run on directly, as long as a wK instance is running in background

yarn test-e2e  # For E2E tests

Ava

Both unit tests and E2E tests are run using the Ava test runner and are written in ES6.

import test from 'ava';

test(t => {
	t.deepEqual([1, 2], [1, 2]);
});

Unit Tests

All unit tests live in the app/assets/javascripts/test directory and end with .spec.js.

End-to-End (E2E) tests

All E2E tests live in the app/assets/javascripts/test directory and end with .e2e.js. These tests are executed against a running server with a testing database. E2E tests may use ava's snapshot testing functionality, which has an interface similar to snapshot(key, value). If no value was saved for a key, the given value is saved. Otherwise, the given value is compared to the saved value and the test passes if the values are equal.

For example, the test/enzyme folder contains tests which render react components including data from the server, while using snapshots.

Run E2E Tests

Run docker-compose up e2e-tests

Alternatively:

  1. Switch the default mongo DB in conf/application.conf from play-oxalis to webknossos-testing
  2. Run sbt test.

Handling failed snapshot tests

Check the diff which ava shows. The snapshot change is likely due to code change which may be either right or wrong. If it is wrong, fix the corresponding code. Otherwise, update the snapshots by removing them (yarn remove-snapshots) and rerunning the e2e tests.

Troubleshooting

The tests fail.

Ensure that ...

  • ... you have not another server and/or mongo instance running.
  • ... dependencies are installed (yarn install) and the JS files are transpiled (yarn test-prepare-watch).
  • ... that docker is executed with the necessary rights (sudo might be necessary)
  • ... that the testing DB is up-to-date. Did your PR introduce a new evolution? Apply it manually to the testing DB and export the DB using tools/import_export/export.sh webknossos-testing test/db/.

Docker messed up the file permissions

sudo chown -R $(whoami) webknossosRepository

Replacing / Creating New Snapshots

Whenever there are no snapshot files present, the E2E will generate new snapshots on the first run.

  1. Delete the existing the snapshots `yarn remove-snapshots``
  2. Run the E2E tests once. (see instructions above)
  3. Commit new snapshots.

Test DB

For the E2E tests, the DB dump stored in testdb/ is imported into the oxalis-testing DB. This happens automatically.

In order to change the test db, perform the following steps:

# Drop the play-oxalis db
tools/dropDB.sh

# Import the testdb into play-oxalis
tools/import_export/import.sh play-oxalis testdb

# Do appropriate changes to the db...

# Export play-oxalis, overwriting the existing testdb dump
tools/import_export/export.sh play-oxalis test/db/

CI

All tests are run by our CI on each commit. More details are on the respective wiki page.

Clone this wiki locally