U-Report is a social messaging tool and data collection system developed by UNICEF to improve citizen engagement, inform leaders, and foster positive change. The program sends polls and alerts to its participants, collecting real-time responses, and subsequently publishes gathered data.
To ensure theU-Report app continues to work as developers add more features or change existing functionality, writing tests for every custom built widget should be an integral part of the development process.
Unit tests are handy for verifying the behavior of a single function, method, or class. The test package provides the core framework for writing unit tests, and the flutter_test package provides additional utilities for testing widgets.
Carry out following steps to add a widget test for the tog navigation widget:
[x] Create a new branch from develop called top-navigation-test. Hint: git checkout -b new-branchexisting-branch
[x] Add the test dependency. Confirm flutter_test package is added to pubspec.yaml file under dev_dependencies section.
[x] Create a new file dart file under test/ folder and name it top_navigation_widget_test.dart
[x] Open top_navigation_widget_test.dart file and import following packages:
import ‘package:flutter/material.dart’;import ‘package:flutter_test/flutter_test.dart’;
[x] Write a test for the tab navigation widget.
[x] Combine multiple tests in a group.
[x] Run the tests in terminal using: flutter test test/top_navigation_widget_test.dart
[x] Commit the changes (as a single commit).
[x] Push changes to Github. Hint:git push --set-upstream origin top-navigation-test
To ensure theU-Report app continues to work as developers add more features or change existing functionality, writing tests for every custom built widget should be an integral part of the development process.
Unit tests are handy for verifying the behavior of a single function, method, or class. The test package provides the core framework for writing unit tests, and the flutter_test package provides additional utilities for testing widgets.
Carry out following steps to add a widget test for the tog navigation widget:
develop
calledtop-navigation-test
. Hint: git checkout -bnew-branch
existing-branch
flutter_test
package is added topubspec.yaml
file under dev_dependencies section.test/
folder and name ittop_navigation_widget_test.dart
top_navigation_widget_test.dart
file and import following packages:import ‘package:flutter/material.dart’;
import ‘package:flutter_test/flutter_test.dart’;
flutter test test/top_navigation_widget_test.dart
git push --set-upstream origin top-navigation-test
Hints: https://medium.com/flutterpub/writing-and-running-widget-tests-from-android-studio-d63b9fea21c5 https://flutter.dev/docs/cookbook/testing/unit/introduction