0% found this document useful (0 votes)
15 views

08 Testing

Unit tests test individual functions or classes in isolation and are quick to execute but provide low confidence. Component/widget tests verify the visual and interactive behavior of individual UI components and provide higher confidence than unit tests at a higher maintenance cost. Integration tests verify that all components work together as expected and provide the highest confidence but are the slowest to execute and have the highest maintenance cost. Continuous integration runs tests automatically after code changes to catch errors early. Popular Flutter testing packages include flutter_test for unit and widget testing, test for general Dart testing, mockito for mocking dependencies, and integration_test for full app testing.

Uploaded by

ta.afridii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

08 Testing

Unit tests test individual functions or classes in isolation and are quick to execute but provide low confidence. Component/widget tests verify the visual and interactive behavior of individual UI components and provide higher confidence than unit tests at a higher maintenance cost. Integration tests verify that all components work together as expected and provide the highest confidence but are the slowest to execute and have the highest maintenance cost. Continuous integration runs tests automatically after code changes to catch errors early. Popular Flutter testing packages include flutter_test for unit and widget testing, test for general Dart testing, mockito for mocking dependencies, and integration_test for full app testing.

Uploaded by

ta.afridii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Testing (Flutter) Apps

CS 442: Mobile App Development

Michael Lee <lee@iit.edu>


Why should we write tests?
Types of tests
• Unit tests
• Component/Widget tests
• Integration tests
Unit test
• Tests a single function or class (“unit”)
• Verify correct behavior with di erent input and conditions/state
• May depend on external dependencies (e.g., le data, database)
• External dependencies may be problematic!
• Slow down testing (e.g., http, remote database servers)
• External exceptions may break tests (but units are not at fault)
ff
fi
“Mock” dependencies
• Instead of using real/live external dependencies, create mock versions
• Emulate the live version, but without risk of slowdown/ akiness

fl
Component/Widget test
• Tests a single UI component (Flutter Widget)
• Very correct visual and interactive aspects
• Requires simulating “lifecycle” events (e.g., building widget tree, performing
layout) and user input / asynchronous events

• Flutter has comprehensive widget-testing facilities


Integration test
• Tests large portions of or the entire app
• Verify that all widgets, underlying logic, and external dependencies work
together (integrate) correctly

• Recording behavior over test may be used to pro le app performance


• Typically run in an emulator

fi
Trade-offs

Unit Widget Integration

Con dence Low Higher Highest

Maintenance cost Low Higher Highest

Dependencies Few More Most

Execution speed Quick Quick Slow


fi
Continuous Integration (CI)
• Service that runs tests automatically after each substantial code update
• Typically on new commits/pushes/merges
• Critical part of DevOps!
Flutter testing packages
• utter_test: the o cial testing library from Flutter
• Unit and Widget testing utilities
• test: general-purpose Dart testing library
• Unit tests for both pure Dart & Flutter
• mockito: object mocking library
• integration_test: for app-level testing
• Multi-widget/screen tests; can also be used for pro ling
fl
ffi
fi

You might also like