Understanding ExUnit

When you’re testing with Phoenix, the framework builds default tests for you that help you keep the basic structure of your tests straight. Those templates even go a long way toward showing you how to build tests to cover your MVC code. Still, it’s best to start at the beginning: a walkthrough of using ExUnit, Elixir’s testing framework. Let’s take a look at a basic Elixir test, one without Phoenix involved at all.

ExUnit has three main macros. The setup macro specifies some setup code that runs once before each test. The test macro defines a single isolated test. The assert macro specifies something we believe to be true about our code. If the assertion is true, the test passes. If it’s false, the test fails. Either way, ...

Get Programming Phoenix 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.