Testing Documentation - bounswe/bounswe2024group1 GitHub Wiki

Testing Strategy Documentation

Overview

This document outlines the testing strategy for the project to ensure the reliability, accuracy, and performance of the product. The project employs a testing approach centered on unit testing for both backend and frontend components, with the use of mock data to isolate and validate the functionality of individual units.


Testing Strategy

Unit Testing

Unit tests are designed to verify the smallest testable parts of the application, such as functions, methods, or components. These tests are isolated from external dependencies, ensuring precise and reliable testing of specific functionality.

Mock Data

Mock data is used extensively in unit tests to simulate external dependencies, such as databases, APIs, or middleware, without requiring the actual services. This approach ensures:

  • Isolation of the unit under test.
  • Faster test execution.
  • Easier debugging.

Goals of the Testing Plan

  1. Validate Core Functionality: Ensure that each unit behaves as expected for various inputs.
  2. Maintain Code Quality: Provide quick feedback to developers to catch issues early in the development process.
  3. Enable Regression Testing: Detect unintended side effects when changes are introduced to the codebase.
  4. Ensure Consistency Across Layers: Validate both backend and frontend units for seamless integration.

Tools and Frameworks

Backend:

  • Mockito
  • JUnit 5

Frontend:

  • Vitest
  • React Testing Library

Examples

Backend Testing Example

    @Test
    void getUserById_ShouldReturnUser_WhenUserExists() {
        User user = new User();
        user.setId(1L);
        when(userRepository.findById(1L)).thenReturn(Optional.of(user));

        Optional<User> result = userService.getUserById(1L);

        assertTrue(result.isPresent());
        assertEquals(1L, result.get().getId());
    }

Example: Testing a function that gets a user by id and returns the user.


Frontend Testing Example

async function testAccessibility(ui: React.ReactElement) {
  const container = document.createElement("div");
  document.body.appendChild(container);

  render(ui, { container });

  const results = await axe(container, {
    rules: {
      "color-contrast": { enabled: true },
      "html-has-lang": { enabled: true },
      "aria-roles": { enabled: true },
      "button-name": { enabled: true },
      "image-alt": { enabled: true },
      "link-name": { enabled: true },
    },
  });

  expect(results).toHaveNoViolations();
  document.body.removeChild(container);
}

Example: Testing the accessibility.


This testing plan provides a robust framework to ensure the reliability and quality of the product by leveraging unit testing with mock data for both backend and frontend components.

⚠️ **GitHub.com Fallback** ⚠️