This chapter covers recipes related to testing and debugging Flutter apps.
14.1 Writing Unit Tests
Problem
You want to write unit tests.
Solution
Use API in test package.
Discussion
Unit tests are very important in app development. To write tests in Flutter apps, you need to add
test: ^1.5.3 to the
dev_dependencies section of
pubspec.yaml file. Test files are usually put in the
test directory. The
MovingBox class in Listing
14-1 is the class to test. The
move() method
updates the internal
_offset variable.
class MovingBox {
MovingBox({Offset initPos = Offset.zero}) : _offset = initPos;
Offset _offset; ...