In this team exercise, you will add automated tests to your project. Your tests should verify important behavior at multiple levels of the application:
- Test-driven development (TDD)
- Unit testing
- System testing
- User-interface testing
The goal is not simply to increase the number of tests. Your team should select meaningful behavior, define expected outcomes, and create tests that help prevent regressions as your project changes.
Learning Objectives
After completing this exercise, your team should be able to:
- Use a test-driven development workflow for a small feature or bug fix.
- Write unit tests for isolated application logic.
- Write system tests that verify multiple application components work together.
- Write UI tests that simulate user interactions.
- Run the project’s tests through an
npm testcommand. - Explain the difference between unit, system, and UI tests.
Required Testing Levels
Part I: Test-Driven Development
Use TDD to implement or improve one meaningful feature, validation rule, or bug fix for small feature/issue.
Follow the Red–Green–Refactor cycle:
- Red: Write a test that describes the expected behavior. Confirm that it fails.
- Green: Write the smallest amount of production code needed to make the test pass.
- Refactor: Improve the code structure while keeping all tests passing.
Document the TDD process in your README or testing document. Include:
- The requirement, feature, or behavior being implemented.
- The initial failing test.
- The production-code change that made the test pass.
- Any refactoring performed.
Part II: Unit Testing
Unit tests verify a small unit of code in isolation, such as a function, class, service method, or validation rule.
Your team must create at least four unit tests covering at least two different units of code.
Good unit-test targets include:
- Price or cost calculations.
- Input-validation functions.
- Permission checks.
- Search or filtering logic.
- State transition rules.
Part III: System Testing
For this assignment, a system test verifies that multiple parts of your application work together to complete a feature. For example, a system test may exercise an API endpoint, its service logic, and its data-access layer. At a minimum, it tests two functions/methods that make up one feature.
Your team must create at least two system tests.
Examples:
- A request to create a new book loan returns the correct response and stores the loan.
- A user can create a study group and retrieve it through the application API.
- An invalid request returns the expected error status and message.
- A user that doesn't have permissions can not make changes.
Part IV: UI Testing
UI tests verify that a person can complete an important task through the interface.
Your team must create at least two UI tests covering at least one complete user story.
Examples:
- As a user I want to fill out and submit a form and then see confirmation or an error message.
- As a user I want to search for an item and seee matching results.
- As a user I want to log in and see the appropriate protected content.
UI tests should verify what the user can see or do. Avoid testing implementation details such as a component’s internal state.
Note: For groups using react native, the UI testing can be component-level tests (React Testing Library).
Test Tools
Select tools that fit your project’s technology stack. Common options include:
| Testing Level | Possible Tools |
|---|---|
| Unit and system testing | Jest, Vitest, Mocha, Supertest |
| React UI testing | React Testing Library with Jest or Vitest |
| Browser-based UI testing | Playwright or Cypress |
Your team may use different tools if they are appropriate for your technology stack.
Test Scripts
Configure your project so the test suite can be run from the command line.
At minimum, your project package.json should provide:
{
"scripts": {
"test": "your-test-command"
}
}
If you use a monorepo, document the command required to run tests for each workspace. Examples: npm test npm run -w express-backend test npm run -w react-frontend test
Documentation Requirements
Add a TESTING.md file or a Testing section in your project README. Include:
- The testing tools your team selected for each type of test.
- Instructions for installing dependencies and running tests.
- A short description of each required testing level.
- The feature, rule, or bug fix developed using TDD.
- Any external services, environment variables, seed data, or test databases required.
- Known testing limitations or future tests your team would add.
Turning It In
Submit the URL for your team’s GitHub repository to the Canvas assignment. Your repository must include:
- A working test command in package.json.
- Documentation for running the tests in README.
- Evidence of the TDD workflow in README.
Only one submission per team is required.