Asynchronous Programming Flashcards
(27 cards)
single process thread
synchronous
multiple processes coordinating and running parallel with each other
asynchronous
in this type of programming, callbacks are used in general
asynchronous
represents a potential value or error that will be available at some time in the future
Future class
provides a more linear and readable way to write asynchronous code
async/await
reduces the need for nested call backs or .then() chains
async/await
use cases to consider in implementing asynchronous programming (4)
- reading data from a file asynchronously
- receiving data from a network socket
- listening to events from a sensor
- handling a continuous flow of data
a continuous sequence of asynchronous events
stream
blocking operations while in progress, the program is unresponsive to other elements
synchronous
non-blocking; uses callbacks, futures, and streams to notify the program when they’re finished
asynchronous
importance of testing (3)
- ensures app quality - features, UX
- reduces bugs - errors
- maintainability - incremental
types of testing (3)
- unit testing
- widget testing
- integration
flutter package to use for testing
flutter_test
what type of testing is being shown by the sample code
void main() { test('should double the number', () { // Arrange int input = 5; // Act int result = doubleNumber(input); // Assert expect(result, 10); }); test('should handle zero', () { expect(doubleNumber(0), 0); }); test('should handle negative numbers', () { expect(doubleNumber(-3), -6); }); }
unit testing
a testing method where individual components of an application are tested to verify their correctness
unit testing
what type of testing is being shown by the sample code
void main() { testWidgets('should display the greeting with the name', (WidgetTester tester) async { // Arrange String testName = 'Flutter User'; // Act await tester.pumpWidget(MaterialApp( // Wrap the widget in a MaterialApp home: GreetingWidget(name: testName), )); // Assert expect(find.text('Hello, $testName!'), findsOneWidget); }); }
widget testing
a testing method used to verify if individual widgets function as expected
widget testing
a testing method that verifies how different modules or components of an application interact and communicate when combined
integration testing
% of code executed when your tests are ran
code coverage
what is a reasonable code coverage
75% to 90%
flutter command to see code coverage
flutter test –coverage
pros of unit testing (3)
- small, fast, isolated
- easy to write
- early detection
cons of unit testing (3)
- limited to scope
- need to setup
- refactoring
pros of widget testing (3)
- tests ui
- simulate user interaction
- more comprehensive