Testing Create Operation
Learn how to test queries in the testing_ecto application.
We’re going to start by looking at part of the logic file with our queries. The file, called Users, contains the basic CRUD actions:
create/1get/1update/2delete/1
The file lib/users/users.ex in testing_ecto is provided:
create/1
The create/1 function in testing_ecto/lib/users/users.ex look like this:
It’s pretty basic, as most CRUD queries are. As a result, testing it won’t be very complicated, either.
Writing tests
Let’s set up a new file at testing_ecto/test/users/users_test.ex.
Success path test
First, we’ll write a success path test.
In it, set up a basic test file structure and then add a describe block for create/1 and our first test:
Let’s go through our test step-by-step:
-
Observe the common setup block at line 7. Because this test file is for our queries, we can safely assume that every test will require a database connection. ...