Google Flutter Google Flutter Testing 1 — Questions and Answers
Question 1: Which type of Flutter test runs entirely in the Dart VM without a device and tests a single class or function?
- Widget test
- Integration test
- Unit test (Correct answer)
- Golden test
Correct answer: Unit test
Unit tests run in the Dart VM, testing individual functions or classes in isolation without any Flutter framework involvement.
Question 2: What Flutter test type verifies that a widget renders and interacts correctly using a test environment?
- Unit test
- Widget test (Correct answer)
- Integration test
- Smoke test
Correct answer: Widget test
Widget tests (also called component tests) test a single widget using the WidgetTester API in a simulated environment.
Question 3: Which Flutter test type runs the full app on a real device or emulator to test end-to-end flows?
- Unit test
- Widget test
- Integration test (Correct answer)
- Golden test
Correct answer: Integration test
Integration tests run the full app and use the flutter_test or integration_test package to simulate user interactions end-to-end.
Question 4: What does WidgetTester.pump() do in a Flutter widget test?
- Rebuilds the entire widget tree from scratch
- Advances the frame clock and processes pending animations/microtasks (Correct answer)
- Navigates to the next screen
- Simulates a tap gesture
Correct answer: Advances the frame clock and processes pending animations/microtasks
pump() triggers a single frame rebuild, processing pending setState calls and microtasks so the widget tree reflects updated state.
Question 5: Which method do you use to find a widget by its type in a Flutter widget test?
- find.text()
- find.byType() (Correct answer)
- find.byKey()
- find.byWidget()
Correct answer: find.byType()
find.byType() locates widgets of a specified type in the widget tree during a test.
Question 6: What is a golden test (snapshot test) in Flutter?
- A test that verifies widget performance metrics
- A test that compares widget rendering to a saved reference image (Correct answer)
- A test run on a golden (production) device
- A test that measures startup time
Correct answer: A test that compares widget rendering to a saved reference image
Golden tests render a widget and compare the output pixel-by-pixel against a saved reference image to catch visual regressions.
Which type of Flutter test runs entirely in the Dart VM without a device and tests a single class or function?