Wrapping Up

Testing Elixir — by Andrea Leopardi, Jeffrey Matthias (53 / 80)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Testing Delete | TOC | Chapter 6 Testing Phoenix 👉

In this chapter, we covered the basic CRUD functions and how to test them. We looked at using a common setup source, a factory. We saw how to make thorough assertions on return values and the data in the database. While no two applications will have exactly the same functionality, these examples lay out the basics that you can build on to make sure your queries are covered by your tests.

Between Chapter 4, Testing Ecto Schemas, and this chapter, we’ve discussed the main concerns you should keep in mind when testing your Ecto code. As you build bigger and more complicated query code, you just need to remember that your tests need to cover both the return values and the side effects. Failing to check the side effects (changes in the database) is one of the most common mistakes we see, and it’s the most important part of testing your query code.

In the next chapter, we’ll move on to testing a Phoenix application, building on all of the concepts we’ve laid out here and in the previous chapters.

Footnotes

[36] https://hex.pm/packages/ex_machina

Copyright © 2021, The Pragmatic Bookshelf.

👈 Testing Delete | TOC | Chapter 6 Testing Phoenix 👉

Testing Elixir by Andrea Leopardi, Jeffrey Matthias can be purchased in other book formats directly from the Pragmatic Programmers. If you notice a code error or formatting mistake, please let us know here so that we can fix it.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.