Howto write tests for SCM-Manager
SCM-Manager supports many kinds of tests to prove the functionality and integrity of the source code. This guide gives a peek how the different classes and components should be tested.
Java Unit Tests
SCM-Manager is already about 10 years in development. There are still many unit tests written with JUnit 4. Whenever such areas are being worked on, the tests should be migrated to JUnit 5.
Adding or changing logic in Java classes must always be backed up with meaningful unit tests. We strongly recommend using JUnit 5 with the optional extensions MockitoExtension.class for mocking and ShiroExtension.class for permission handling. For assertions we use AssertJ most of the times.
Frontend Component Tests
For frontend components tests we differ between UI tests and API tests.
Writing fitting and responsive components can be easily done using our Storybook in the module
The storybook gives a nice overview of the existing components and prevents visual regression.
Just start it with
yarn storybook inside
ui-components and have a look at the existing code on how our stories are written.
For logic tests and api call tests we prefer jest respectively fetch-mock-jest.
Writing integration tests in Java we also suggest JUnit 5. This kind of integration tests are used to test whole modules via the REST-API. Parameterized tests can check integrations with different inputs/configs.
Integration Test Runner
As we needed to also test integration via the UI/Frontend and especially integrations between different plugins we created our own integration-test-runner. This test-runner is based on cypress which supports cucumber styled behaviour driven testing. Find more about it here:
Also some test examples: