idcoop/docs/dev/testing.md
Olivier 'reivilibre eb0a417c35 Add test scaffolding
Signed-off-by: Olivier 'reivilibre <olivier@librepush.net>
2024-07-06 14:31:06 +01:00

1.2 KiB

Testing

Testing approach

Unit tests

Unit tests should live inside a module in the code unit they are testing, gated behind #[cfg(test)].
This is fairly common Rust practice.

There is no hard and fast rule for the granularity of the unit tests, but they should test the smallest amount of logic that is simple to test, but no smaller.
In practice this means that unit tests should be at the function-level where this makes sense, or at the struct-level if this makes more sense.

For now, avoid the use of test mocks, but use them if it makes strong sense to do so.

Integration tests

Integration tests should live in the tests/ directory.

In general, each test will get its own throwaway Postgres database.

Snapshot tests

Some of the integration tests will compare snapshots (of e.g. HTML) against a gold standard.

When a new snapshot is created, the output should be manually verified, including in a browser if necessary.

It goes without saying that all snapshot changes should be expected; if they are not then treated as failures.

End-to-end tests

idCoop doesn't currently have end-to-end tests but this is on the wishlist for the future.

Will eventually look into Playwright etc.