© Fu Cheng 2019
Fu ChengFlutter Recipeshttps://doi.org/10.1007/978-1-4842-4982-6_14

14. Testing and Debugging

Fu Cheng
(1)
Sandringham, Auckland, New Zealand
 
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; ...

Get Flutter Recipes: Mobile Development Solutions for iOS and Android now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.