O'Reilly logo

Programming Phoenix by Jose Valim, Bruce Tate, Chris McCord

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required