Search⌘ K
AI Features

Example-based Tests

Explore example-based testing in Elixir with ExUnit to understand how predefined input examples validate functions. Learn to write tabular tests that specify input-output pairs for clear testing of edge cases and typical scenarios, while recognizing their limitations in exposing unknown cases.

Example-based tests

When writing tests, we usually write something that we could call example-based tests. In this lesson, we’ll have a new look at them from the perspective of the inputs that we feed to our code. We’ll define terminology to identify example-based tests, which will help us later compare them to property-based tests.

Let’s start with an example. Let’s say we want to test that the Enum.sort/1 function correctly sorts lists. Take a look at property_based_testing/sorting/test/example_based_sort_test.exs ...