Writing our unit tests

If we really want to be able to mark this code as complete, we need to start testing our code, to get a better picture of if it is working as expected and performing all of the necessary functions we need. We'll create a couple of new folders and a new file, test/vocial/votes/votes_test.ex, which will be in charge of testing our Context code.

Like most Phoenix code that we write, we'll start off by defining a test module. We'll also need some helper macros defined in our app's DataCase module and a few alias statements to make our lives easier. So we'll start out with:

defmodule Vocial.VotesTest do use Vocial.DataCase alias Vocial.Votesend

This will be the beginning of our test code. Next we're going to write some code ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.