Search⌘ K
AI Features

Write Automated Acceptance Tests

Explore how to write automated acceptance tests for real-time features in Phoenix and Elixir applications. Understand how to test live product updates, stock-level changes, and ensure your application's real-time capabilities function correctly end-to-end.

We'll cover the following...

Product page tests

The Sneakers23 store has two main real-time components: live sneaker drops and stock-level updates. We will write acceptance tests for each feature to ensure our application works end-to-end.

We need to make a small change to our Inventory.Server module before writing our tests. The application uses a single Inventory.Server process that holds the current inventory and stock levels. Our Hound tests will execute in the same environment as our tests and will pull the inventory from the global inventory process. Currently, this process loads its state at startup, and we do not have a way to change the loaded inventory. We need to add a function—so add the following function to the bottom of the Inventory.Server module.

Elixir
# sneakers_23/lib/sneakers_23/inventory/server.ex
if Mix.env() == :test do
def handle_call({:test_set_inventory, inventory}, _from, _old) do
{:reply, {:ok, inventory}, inventory}
end
end

This code uses a compile-time check to guarantee that the message will only be handled in ...