Testing Documentation - bounswe/bounswe2024group1 GitHub Wiki
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.
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 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.
- Validate Core Functionality: Ensure that each unit behaves as expected for various inputs.
- Maintain Code Quality: Provide quick feedback to developers to catch issues early in the development process.
- Enable Regression Testing: Detect unintended side effects when changes are introduced to the codebase.
- Ensure Consistency Across Layers: Validate both backend and frontend units for seamless integration.
Backend:
- Mockito
- JUnit 5
Frontend:
- Vitest
- React Testing Library
@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.
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.