Test Phoenix Requests

It’s more complex to test endpoints than it is to test pure functions or Ecto queries, but Phoenix provides several helper functions to make it as easy as possible. You’ll find more complexity in deciding what to test (complex HTML responses, valid versus invalid parameters, full integration testing versus mock testing, and so on) than you will in writing the actual tests. However, lean toward testing more than less so that you have confidence in your system.

We’ll set up the test module and then walk through a few types of controller tests. But first, let’s create a little helper to make our tests simpler.

Create Helper Factory

It’s common as you write tests to create the same test data over and over again. Usually, setting ...

Get From Ruby to Elixir 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.