Chapter 6: Building Features - Search

Besides testing whether the filters themselves work or not, it seems equally or even more important whether you get the search results you’re asking for. How would you unit test the filter/ searchText on the animals result?

Hi, @wessoll

You can unit test the different parts of the code. So, for example, if you want to test if AnimalSearcher does get the correct parameters from the view model (text, age and type), you can write a unit test where a mock struct implements AnimalSearcher and stores those parameters. You can then check in your unit test if they match what the view model sent.

You can also test if the values your mock object returns are being correctly stored in CoreData. You can use a mock object to return a set of animals, and then check the test database if they match those animals.

Now, if you want to test if the results you’re getting from the web server are being stored correctly depending on the filter parameters, then you’re need something more robust like an end-to-end test.

1 Like