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

14. Testing and Debugging

Fu Cheng1 
(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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.