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
### JUnit 4
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.
### 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](https://github.com/mockito/mockito) for mocking
and [ShiroExtension.class](https://github.com/sdorra/junit-shiro-extension) for permission handling.
For assertions we use [AssertJ](https://assertj.github.io/doc/#overview-what-is-assertj) most of the times.
- [Example Link Enricher Tests](https://github.com/scm-manager/scm-manager/blob/af8980de19b580f80c8ec5f72428071d6b45dbfb/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/api/v2/resources/RepositoryLinkEnricherTest.java)
For frontend components tests we differ between UI tests and API tests.
### Storybook
Writing fitting and responsive components can be easily done using our [Storybook](https://github.com/storybookjs/storybook) in the module `ui-components`.
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](https://github.com/facebook/jest) respectively [fetch-mock-jest](https://github.com/wheresrhys/fetch-mock-jest).
- [Example Jest Tests](https://github.com/scm-manager/scm-manager/blob/9e45d8255d75712269407ebf932cb2a8990a7c17/scm-ui/ui-webapp/src/users/components/userValidation.test.ts)
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:
- [Integration Test Runner](https://github.com/scm-manager/integration-test-runner)
- [Example Test Features](https://github.com/scm-manager/scm-editor-plugin/blob/d9e1e625d6d36ffddc49a758c4ca23ff0dfaffe9/src/test/e2e/cypress/integration/create.feature)
- [Example Test Definitions](https://github.com/scm-manager/scm-editor-plugin/blob/d9e1e625d6d36ffddc49a758c4ca23ff0dfaffe9/src/test/e2e/cypress/support/step_definitions/scm-editor-plugin.js)