Chapter 6. Testing

 

This chapter covers

  • Writing unit tests
  • Writing fuzz tests
  • Testing update functions
  • Testing view functions

Our Photo Groove application has been delighting users in production for a while now, and things have settled down on the development team. Our manager has left for vacation with vague instructions to “keep the lights on,” and we find ourselves with time to revisit some of the corners we cut when shipping Photo Groove.

At this point, we know we’ll be maintaining this application for the long haul. We’ll need to add new features, improve existing ones, and do both without introducing bugs to the existing feature set. That isn’t easy! The longer our application is around, the more important it will be that the code we write is not just reliable, but also maintainable.

As we saw in chapter 3, Elm’s compiler is an invaluable tool for maintainability. It can assist us by finding syntax errors and type mismatches before they can impact our end users, and this is even more helpful after we make a big change to our code.

However, the compiler has no way of knowing how our business logic is supposed to work. We’ll need to use a different tool to verify that our business logic is working as expected, and elm-test is great for that! In this chapter, you’ll learn how to use elm-test to write automated tests that verify our business logic, including the following:

  • Testing our JSON decoding logic
  • Testing our update logic
  • Testing our view logic

6.1. Writing unit tests

6.2. Writing fuzz tests

6.3. Testing views

Summary