...

/

Introduction to Unit Tests

Introduction to Unit Tests

Get introduced to Unit Tests in Elixir.

For most engineers, the testing experience starts with the unit test. Unit tests are the easiest to write because:

  • They have a limited focus.
  • They are less complicated than other tests.
  • They form the basis for all testing.

In this chapter, we’ll learn how to define the scope of our tests, write tests for functional code, and structure a test file. Then we’ll explore some ways to isolate our code under tests.

Defining the unit

A unit test is a software test that focuses on a subset of an application, often removing the overarching context for how the code is used.

It’s common to find a unit test focused on a single function and just the logic in that function, possibly encapsulating private functions available to it. Sometimes it makes more sense to include code from multiple modules, or processes, inside the scope of our unit tests, expanding the scope of the unit.

...