Testing the XKCD App: Using Mock Objects

Testing the XKCD app presents a challenge: the app relies on external variables: an Internet connection needs to be present and the app needs to be able to connect to the XKCD servers (which need to be up) to work. The issue with that is that we may need to only test a small part of our app (especially during unit testing) without needing to interface with anything else, and we need to mock files since we can’t access them anyway. To do this, developers usually resort to building mock objects, which are objects that simulate the features provided by the external interface while not requiring that interface.

Building mock objects isn’t language or framework specific, but Google has developed a Flutter ...

Get Programming Flutter now with O’Reilly online learning.

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