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 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.