Unit Tests
(For each method, there are one or more test cases. A test case consists of input parameter values and expected results. All external classes should be stubbed using mock objects.)
Purpose
The Test Procedures describe the test approach and the tests to be performed to verify the requirements specified in the Requirements Document.
Library Explanation
We chose Jest along with the React Testing Library.
Jest
- Primary Testing Framework
- Selected because:
- Code coverage reporting
- Mocking ability
- Perfect integration with React and Next.js
React Testing Library
- UI Testing Utility
- Selected because:
- Simulates user testing
Setup
-
Required Dependencies
{
"jest": "^27.0.0",
"@testing-library/react": "^12.0.0",
"@testing-library/jest-dom": "^5.0.0"
} -
Running Tests
# Run all tests
npm test
# Run with coverage
npm test -- --coverage
# Run specific test file
npm test -- completionPage.test.tsx
Test Structure
describe('Component/Method Name', () => {
beforeEach(() => {
// Setup code
});
it('should do something specific', () => {
// Arrange
// Act
// Assert
});
});
Test Cases and Implementation
Unit tests for GamePlay are located in StoryQuest/app/Gameplay/__tests__/gameplay.test.tsx
.