Documentation Index
Fetch the complete documentation index at: https://mintlify.com/antinomyhq/forge/llms.txt
Use this file to discover all available pages before exploring further.
Writing Tests
Forge helps you write high-quality tests quickly, following best practices and conventions for your specific technology stack.Basic Test Generation
Ask Forge to generate tests for your code:- Analyze the code to understand its behavior
- Generate comprehensive tests covering:
- Happy path scenarios
- Edge cases
- Error conditions
- Follow testing conventions for your language/framework
- Include appropriate assertions and mocks
Test-Driven Development (TDD)
Use Forge to practice TDD:Testing Patterns and Best Practices
Three-Phase Test Pattern
Forge follows the standard three-phase test pattern:Using Fixtures
Forge creates reusable test fixtures:- Generic, reusable test data
- Builder pattern with
derive_setters - Default values for required fields
- Methods to customize specific fields
Descriptive Variable Names
Use clear names likefixture, actual, and expected:
Language-Specific Testing
Rust Testing
Forge follows specific conventions for Rust:- Tests are in the same file as source code
pretty_assertionsis used for better error messagesunwrap()is used in tests (not production code)expect()with messages for clarity when needed- Full object comparison with
assert_eq!
JavaScript/TypeScript Testing
For JavaScript projects:- Proper test setup with required imports
- Mocks for dependencies
- Async/await handling where needed
- Component rendering and interaction tests
Python Testing
- Test fixtures with pytest decorators
- Proper assertions using pytest features
- Mock objects for external dependencies
- Parameterized tests for multiple scenarios
Real-World Testing Scenarios
Scenario 1: Testing API Endpoints
Scenario 2: Testing React Components
- Component rendering with different props
- User interactions (clicks, form submissions)
- State changes
- API calls and loading states
- Error handling and edge cases
Scenario 3: Testing Business Logic
- Basic calculations
- Discount applications
- Tax calculations
- Edge cases (zero amounts, negative values)
- Boundary conditions (minimum/maximum values)
Test Coverage and Completeness
Ensuring Complete Coverage
- Identify untested code paths
- Suggest additional test cases
- Generate tests for missing scenarios
- Highlight edge cases that need coverage
Edge Case Testing
Forge excels at identifying edge cases:- Null/undefined inputs
- Empty strings
- Invalid formats
- Boundary dates (leap years, timezone changes)
- Locale-specific issues
Mocking and Test Doubles
Creating Mocks
- Mock objects that match the real API interface
- Configurable responses for different test scenarios
- Verification methods to check mock calls
Dependency Injection for Testing
- Constructor injection
- Interface-based dependencies
- Configurable behavior for tests
Integration and E2E Testing
Integration Tests
- Set up complete test environments
- Test interactions between components
- Verify end-to-end functionality
- Clean up test data afterward
Database Testing
- Setting up test databases
- Creating seed data
- Running migrations
- Cleaning up after tests
- Testing transactions and rollbacks
Performance Testing
- Benchmark tests with various data sizes
- Performance assertions
- Comparison with baseline measurements
- Memory usage tracking
Testing Best Practices
- Test behavior, not implementation: Focus on what code does, not how
- One assertion per test: Keep tests focused and specific
- Use descriptive test names: Name should explain what’s being tested
- Make tests independent: Tests shouldn’t depend on each other
- Keep tests fast: Unit tests should run in milliseconds
- Use fixtures: Create reusable test data
- Test edge cases: Don’t just test the happy path
Test Maintenance
Updating Tests After Refactoring
- Analyze changes in the implementation
- Update test setup to match new interfaces
- Preserve test intent while adapting structure
- Ensure all tests still pass
Fixing Failing Tests
- Should the implementation change to match tests?
- Or should tests update to match new behavior?
- Are the tests revealing actual bugs?
Testing Anti-Patterns to Avoid
Don’t: Test Implementation Details
Bad:Don’t: Share State Between Tests
Bad:Don’t: Use Multiple Assertions for Parts
Prefer full object comparison: Bad:Common Testing Commands
| Task | Example Prompt |
|---|---|
| Write unit tests | Write tests for the UserService class |
| Test coverage | What edge cases am I missing for this function? |
| Create mock | Create a mock for the database connection |
| Integration test | Write an integration test for the checkout flow |
| Fix tests | Help me fix these failing tests |
| TDD | Write a test for a function that validates phone numbers |
Verification After Writing Tests
Always verify your tests work:Next Steps
- Learn about Code Review including test quality
- Explore Refactoring to improve testability
- Review Best Practices for development workflows