Students will extend their existing Employee Management API by using the TDD cycle:
- Write a test
- Run the test
- See it fail
- Write the code
- Run the test again
- Refactor if needed
Students already have:
GET /employeesPOST /employeesGET /employees/{id}PUT /employees/{id}DELETE /employees/{id}
They also have a simple in-memory or MongoDB-backed employee app.
For every new feature:
- Step 1: Write test first
- Step 2: Run test and confirm failure
- Step 3: Implement feature
- Step 4: Run tests again
- Step 5: Clean up code if needed
GET /employees?department=IT- Return only employees from the given department
- If no employees match, return an empty list
- department exists
- department does not exist
- multiple employees in same department
GET /employees?name=John- Return matching employees
- Partial match is a bonus
- Case-insensitive match is a bonus
- exact name match
- no match found
- optional: partial name match
Two employees cannot have the same email.
- If duplicate email is submitted, return error
- Suggested status code:
400
- create first employee with email
- create second employee with same email
- verify second request fails
Employee must have:
- name
- role
- department
- Missing field returns
400or validation error
- missing name
- missing email
- missing role
- missing department
GET /employees/summary{
"total_employees": 5,
"departments": ["IT", "HR", "Finance"]
}- returns correct total count
- returns unique department list
Each student or team must complete at least:
- 3 new features
- test cases for each feature
- proof that tests failed before code was added
- proof that tests passed after implementation
test_main.py
pytestfastapi.testclient.TestClient
def test_create_employee_duplicate_email():
...- test fails
- check whether email already exists
- test passes
Students must submit:
-
Updated application code
-
test_main.py -
Screenshot or terminal output showing:
- failing tests first
- passing tests later
-
Short note answering:
- Which features did you add?
- Which test did you write first?
- What bug or failure did the test catch?
Use AI, but follow this rule:
Do not ask AI to only write the feature. Ask AI to write the test first.
Write pytest test cases first for my FastAPI employee app.
I want to add:
1. filter by department
2. duplicate email validation
3. employee summary endpoint
Keep tests beginner-friendly.
Explain what each test is checking.
Do not write the feature code yet.
Then after tests fail:
Now implement only the code needed to make these tests pass.
Keep the code simple and readable.
Explain what changed.