Files
privacy.sexy/docs/tests.md
undergroundwires ae75059cc1 Increase testability through dependency injection
- Remove existing integration tests for hooks as they're redundant after
  this change.
- Document the pattern in relevant documentation.
- Introduce `useEnvironment` to increase testability.
- Update components to inject dependencies rather than importing hooks
  directly.
2023-08-15 18:11:30 +02:00

3.7 KiB

Tests

There are different types of tests executed:

  1. Unit tests
  2. Integration tests
  3. End-to-end (E2E) tests

Common aspects for all tests:

  • They use Mocha and Chai.
  • Their files end with .spec.{ts|js} suffix.

💡 You can use path/module alias @/tests in import statements.

Unit tests

  • Unit tests test each component in isolation.
  • All unit tests goes under ./tests/unit.
  • They rely on stubs for isolation.
  • Unit tests include also Vue component tests using @vue/test-utils.

Unit tests structure

Unit tests naming

  • Each test suite first describe the system under test.
    • E.g. tests for class Application.ts are all inside Application.spec.ts.
  • describe blocks tests for same function (if applicable).
    • E.g. test for run() are inside describe('run', () => ..).

Act, arrange, assert

  • Tests use act, arrange and assert (AAA) pattern when applicable.
  • Arrange
    • Sets up the test case.
    • Starts with comment line // arrange.
  • Act
    • Executes the actual test.
    • Starts with comment line // act.
  • Assert
    • Elicit some sort of expectation.
    • Starts with comment line // assert.

Integration tests

  • Tests functionality of a component in combination with others (not isolated).
  • Ensure dependencies to third parties work as expected.
  • Defined in ./tests/integration.

E2E tests

  • Test the functionality and performance of a running application.
  • Vue CLI plugin e2e-cypress configures E2E tests.
  • Test names and folders have logical structure based on tests executed.
  • The structure is following:
    • cypress.config.ts: Cypress configuration file.
    • ./tests/e2e/: Base Cypress folder.
      • /specs/: Test files named with .spec.js extension.
      • /plugins/index.js: Plugin file executed before loading project.
      • /support/index.js: Support file, runs before every single spec file.
      • (Ignored) /videos: Asset folder for videos taken during tests.
      • (Ignored) /screenshots: Asset folder for Screenshots taken during tests.