0% found this document useful (0 votes)
54 views3 pages

4.1 L04-S04-unit-testing PDF

The document provides instructions to fix a unit test for a template app. It involves opening the widget_test.dart file, updating the app reference, removing unused code and comments to leave the basic test structure. It then describes replacing the find.text() calls to test searching for cats, which should find one widget, and dogs, which should find nothing. Finally, it notes that running flutter test will execute the updated unit test and confirm all tests pass.

Uploaded by

gdgdfg
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)
54 views3 pages

4.1 L04-S04-unit-testing PDF

The document provides instructions to fix a unit test for a template app. It involves opening the widget_test.dart file, updating the app reference, removing unused code and comments to leave the basic test structure. It then describes replacing the find.text() calls to test searching for cats, which should find one widget, and dogs, which should find nothing. Finally, it notes that running flutter test will execute the updated unit test and confirm all tests pass.

Uploaded by

gdgdfg
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/ 3

Fixing our Template Unit Test

○ Open ./test/widget_test.dart to view the broken Unit test.


○ Update the App reference
○ Remove unused code and comments leaving the following:

import 'package:flutter_test/flutter_test.dart';

import 'package:catbox/main.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(new CatBoxApp());

// Verify that our counter starts at 0.


expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
});
}
Replace Click Test

○ Replace the find.text() that is looking for a change in the click


▻ Search for Cats and confirm we CAN find
▻ Search for Dogs and confirm we CANNOT find

import 'package:flutter_test/flutter_test.dart';

import '../lib/main.dart';

void main() {
testWidgets('app should load cats', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(new CatBoxApp());

// Verify we can find the Header label Cats


expect(find.text('Cats'), findsOneWidget);
expect(find.text('Dogs'), findsNothing);
});
}
Run the Unit Test

Now to run the Unit test simply use the following


command:

$ flutter test
00:05 +1: All tests passed !

You might also like