What Makes CRC Code Testable?

Learn how testing should be done in a Phoenix application.

Why testing is important

Think of a test as a scientific experiment. The experiment’s target is a bit of code, and the thesis is that the code is working. Logically, each test is an experiment that does three things:

  • Sets up preconditions
  • Provides a stimulus
  • Compares an actual response to expectations

That definition is pretty broad and covers a wide range of testing strategies and frameworks. We’re going to write three tests of two specific types. Both types of tests will follow this broad pattern. One of the tests will be a unit test. We’ll write it to verify the behavior of the independent functions that set up the socket. We’ll also write two integration tests that will let us verify the interaction between components: one to test interactions within a LiveView process and another to verify interactions between processes.

The integration tests ...