Debugging Tests
This guide covers strategies and tools for debugging tests in Gradiant.Common Issues
Test Failures
- Async Operation Timing
- Database State
- Mock Reset
Debugging Tools
Console Debugging
Node Inspector
- Start debugger:
- Add breakpoints:
- Use Chrome DevTools (chrome://inspect)
VS Code Debugging
- Create
.vscode/launch.json:
- Set breakpoints in VS Code
- Run “Debug Tests” configuration
Test Environment
Database Debugging
- Enable query logging:
- Inspect database state:
Network Debugging
- Log HTTP requests:
- Debug WebSocket:
Performance Issues
Slow Tests
- Use test timer:
- Profile specific test:
Memory Leaks
- Watch memory usage:
- Clean up resources:
Best Practices
-
Isolate Tests
- Use unique test data
- Clean up after each test
- Reset mocks and spies
-
Meaningful Errors
- Use custom matchers
- Add context to assertions
- Log relevant state
-
Maintainable Tests
- Follow AAA pattern
- Use helper functions
- Keep tests focused