You are on page 1of 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