Cleanup Suites
Cleanup suites run after all other tests to reset application state or clean up test data.
Why Cleanup Suites?
Tests often create data:
- New user accounts
- Orders and transactions
- Uploaded files
- Configuration changes
Cleanup suites help:
- Delete test data
- Reset application state
- Prepare for next test run
- Keep test environments clean
Creating a Cleanup Suite
Step 1: Create the Suite
- Create a new test suite
- Name it "Cleanup" or "Teardown"
Step 2: Mark as Cleanup Suite
- Open suite settings
- Enable Cleanup Suite
- Save
Step 3: Add Cleanup Tests
Create tests that clean up data:
Test: Delete Test User
Steps:
1. Navigate to user management page
2. Search for the test user email
Data: {{global.email}}
3. Click the delete button for the user
4. Confirm deletion in the modal
5. Verify user is deleted
Execution Order
1. Login Suites (if any)
2. Regular Test Suites (in order)
3. Cleanup Suites - Always run last
Cleanup suites run even if earlier tests fail. This ensures test data is always cleaned up.
Common Cleanup Tasks
Delete Created Users
1. Navigate to admin user list
2. Search for test email
Data: {{global.email}}
3. Click delete button
4. Confirm deletion
Remove Test Orders
1. Navigate to admin orders page
2. Filter by test order prefix
3. Select all test orders
4. Click bulk delete
5. Confirm deletion
Reset Configuration
1. Navigate to settings page
2. Click "Reset to defaults"
3. Confirm reset
4. Verify settings are default
Clear Test Files
1. Navigate to file manager
2. Select test upload folder
3. Delete all files in folder
4. Verify folder is empty
Using Global Placeholders
Reference data created during tests:
Earlier Test (Registration):
- Step: Enter email
Data: {{global.email}}
Cleanup Test (Delete User):
- Step: Search for user
Data: {{global.email}}
The same email is used to create and delete the user.
Best Practices
Make Cleanup Idempotent
Cleanup should succeed even if there is nothing to clean:
Good: "Delete user if exists"
Bad: "Delete user" (fails if already deleted)
Order Cleanup Tasks
Delete dependent data first:
1. Delete user's orders
2. Delete user's files
3. Delete user account
Use Admin Access
Cleanup often needs admin privileges:
- Set admin credentials in cleanup suite settings
- Or use a separate admin login in cleanup suite
Do Not Skip on Failure
Cleanup suites should always attempt to run, even if:
- Earlier tests failed
- Login suite failed
- Application is in bad state
Verify Cleanup Succeeded
Add assertions to cleanup tests:
Assertion: Test user no longer exists
Assertion: Test orders are deleted
Multiple Cleanup Suites
You can have multiple cleanup suites for different purposes:
Cleanup - User Data
Cleanup - File Storage
Cleanup - Configuration
They all run after regular suites, in the order they appear.
Cleanup vs Test Data Isolation
Option A: Cleanup Suites
- Create data during tests
- Delete data in cleanup suite
- Simpler setup
- Data visible during debugging
Option B: Unique Data Per Run
- Use
{{run.*}}placeholders for unique data per test - No cleanup needed
- Data accumulates over time
- May need periodic manual cleanup
Recommendation: Combine both approaches:
- Use unique data where possible
- Use cleanup for data that must be removed
Troubleshooting
Cleanup Fails to Find Data
- Test may not have created the data
- Data may have been deleted already
- Global placeholder may have different value
Cleanup Blocked by Dependencies
- Delete dependent records first
- Check for foreign key constraints
- May need API-level cleanup for complex cases
Cleanup Times Out
- Large amounts of data to clean
- Slow deletion process
- Consider batch deletion or API cleanup
Example: Complete Cleanup Suite
Suite: Test Cleanup (Cleanup Suite: enabled)
Test: Remove Test Data
Steps:
1. Navigate to admin panel
Wait Until: Admin dashboard visible
2. Go to user management
3. Search for test users
Data: @test.bug0.com
4. Select all matching users
5. Click "Bulk Delete"
6. Confirm deletion in modal
Wait Until: Deletion complete message
Assertions:
- No test users remain in list
- Success message is displayed