Phoenix Fundamentals

Phoenix makes building robust, high-performance web applications easier and more fun than you ever thought possible.

Phoenix Fundamentals

Testing

Testing ergonomics is perhaps the most impactful factor in determining whether writing tests is an enjoyable part of day-to-day development, or an annoying slog that's neglected until problems arise.

In this area, Phoenix does not disappoint. We'll focus on several useful patterns for unit and acceptance testing, with the aim of making tests quick, easy, maintainiable and intuitive.

  • TestingWelcome Back

    One more recap of what we learned yesterday, to get those fresh in everyone's minds again, and a quick agenda of what we plan to do today.

  • TestingModel Tests

    When working with Ecto, you may notice that your model layer is much thinner than what you're used to. Particularly if you've never used a functional language to build web applications, you may have to get used to your models being a collection of functions, rather than a factory for "record objects". We'll learn about ExUnit, the unit testing library that Phoenix ships with, and focus on a few common model testing needs:

    • Functions that return changesets
    • Validations that are run on said changesets
    • Special types of fields (i.e., virtual fields, fields with default values)
  • TestingEXERCISE: User Model Tests

    Write some user model tests, and most importantly, build tests around our password validation logic from yesterday.

  • TestingController & View Tests

    Sometimes we use Phoenix to render HTML, so we'll look at how we can verify that both our controller and view layers (individually) are doing their job. Together, we'll write some unit tests for the "welcome" pages we made yesterday.

  • TestingJSON API Tests

    Often we use Phoenix Controllers to render JSON. We'll explore some built-in helpers that are well-suited for helping us write tests verifying that the JSON contains what we expect, and touch on a few libraries that make this even easier!

  • TestingEXERCISE: JSON Tests

    1. Build some tests around the StatusControllers JSON endpoints, protecting it from regression
    2. Build a test asserting that our anti-SOAP Plug works as intended