Testing Overview
AppFlowy Editor provides testing utilities that make it easy to:- Test basic editor functions
- Simulate user interactions
- Test custom block components
- Test collaborative features
- Verify document state
Setup
Add testing dependencies to yourpubspec.yaml:
Test File Structure
Mirror your code structure in tests:Basic Editor Testing
Setting Up a Test Editor
Creating Test Documents
Testing Node Operations
Accessing Nodes
Testing Text Insertion
Testing Attributes
Testing Selection
Update Selection
Testing Keyboard Input
Simulating Keyboard Shortcuts
Testing Key Combinations
Testing Custom Components
Widget Test for Custom Block
Testing Transactions
Transaction Application
Testing Undo/Redo
Testing Collaborative Features
Remote Transaction Application
Integration Testing
End-to-End Test
Best Practices
- Use TestWidgetsFlutterBinding: Always initialize in
setUpAll() - Start Testing: Call
await editor.startTesting()before assertions - Pump and Settle: Use
await tester.pumpAndSettle()after state changes - Isolate Tests: Each test should be independent
- Test Edge Cases: Test empty documents, large documents, special characters
- Mock External Dependencies: Mock network calls and file I/O
- Use Descriptive Names: Test names should describe what they test
- Clean Up: Dispose resources in
tearDown()
Testing Checklist
- Basic node insertion and deletion
- Text formatting (bold, italic, etc.)
- Selection and cursor movement
- Keyboard shortcuts
- Undo/redo functionality
- Custom block components
- Transaction application
- Remote transactions (for collaboration)
- Edge cases (empty document, large document)
- Performance under load