How to Write Tests

Learn the benefits and the steps needed to follow for writing tests.

We'll cover the following...

Tests

If there is one thing that every developer probably has an opinion about, it’s testing. We may believe in test-driven development, where we write tests before writing any of our implementation code. Or maybe we follow the practice of code first, test second. We won’t open up any testing philosophy questions in this course. Instead, we’ll look at the available mechanisms for testing our real-time code—and we can apply them using our preferred methodology.

Tests provide us with a higher sense of confidence in our writing code. We can trap complex bugs in robust tests that withstand the test of time. In the ideal world, we can capture any bug in a test and prevent it from happening again in the future.

Phoenix provides a simple and powerful way to write Channel tests. A few basic primitives allow us to quickly write tests of our entire real-time communication stack. We don’t have to worry about the challenges of WebSockets or long polling when we write our tests. Instead, we only have to write tests for the Socket and Channel implementations, which we’ll cover in this section.

Testing Sockets

Every Phoenix ...