April 2024
Beginner to intermediate
224 pages
5h 7m
English
It’s simple to test code that uses database queries. We need to use a special test case that’s provided to us by the Phoenix generator. This includes transactional test cases, which means that our test database is cleaned up after each test.
We’ll test the ContactStore module because it has functions for retrieving and writing data. We will skip SmsMessageStore because it has many more functions. But the book’s provided code (phone_app folder) has tests for the entire application.
Create test/phone_app/conversations/query/contact_store_test.exs and add the following code:
| 1: | defmodule PhoneApp.Conversations.Query.ContactStoreTest do |
| - | use PhoneApp.DataCase, ... |
Read now
Unlock full access