This article is a continuation of the first part TDD in Flutter Part 1: Introduction to Test Driven Development.

Write your first unit test

Let’s consider that you have created an application which fetch data from an API. How can you test that you will be fetching and parsing your data correctly into a model class ?

In this example I am going to use the  JSON Placeholder API. First thing you should do would be to grab some response which you could use for your tests, here’s mine:

{
   "userId":1,
   "id":1,
   "title":"sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
   "body":"quia et suscipit suscipit recusandae consequuntur expedita et cum reprehenderit molestiae ut ut quas totam nostrum rerum est autem sunt rem eveniet architecto"
}

random_user.json

#dart #testing #flutter

TDD in Flutter Part 2: How to write a unit test ?
1.60 GEEK