Overview
Flet testing enables you to:- Launch and interact with Flet apps programmatically
- Find controls by text, icon, type, or key
- Simulate user interactions (taps, text input, etc.)
- Verify control properties and state
- Test async operations with pump and settle
sdk/python/packages/flet/integration_tests/
Setup
Install the testing dependencies:Basic Test Structure
Tests usepytest with async support:
Location: sdk/python/packages/flet/integration_tests/apps/counter/test_counter_app.py:1
Finding Controls
The tester provides multiple finder methods:Find by Text
Find by Icon
Find by Key
Keys are the most reliable way to find specific controls:Find by Type
Simulating User Interactions
Tap/Click
Location:sdk/python/packages/flet/integration_tests/apps/counter/test_counter_app.py:28
Text Input
Multiple Taps
Pump and Settle
pump()
Triggers a single frame update:pump_and_settle()
Waits for all animations and async operations to complete: Location:sdk/python/packages/flet/integration_tests/apps/counter/test_counter_app.py:22
pump_and_settle() with timeout
Testing Counter App
Here’s a complete example testing a counter application: Location:sdk/python/packages/flet/integration_tests/apps/counter/test_counter_app.py:9
Testing Components
Test component-based apps the same way:Testing Async Operations
Testing Authentication
Test Organization
Organize tests by feature:Best Practices
- Use keys for reliable finding - Keys are stable across renders
- Always pump_and_settle() - Ensure app is ready before assertions
- Test user flows, not implementation - Focus on what users do
- Keep tests independent - Each test should run in isolation
- Use descriptive test names - Name tests after the behavior they verify
- Mock external dependencies - Don’t call real APIs in tests
- Test error states - Verify error handling and edge cases
- Use parametrize for similar tests - Reduce code duplication
Running Tests
Continuous Integration
Example GitHub Actions workflow:Next Steps
- Learn about Components for testable architecture
- Explore Hooks for stateful components
- Build Custom Controls with tests