⚠️ This post links to an external website. ⚠️
A test should explain itself. Shared setup callbacks may minimize repetition, but they can obscure the context needed to understand a test's intent. Self-contained tests, which create their necessary state within the test itself, provide clarity by ensuring that all relevant information is in one place. The article criticizes shared setups for complicating test readability and review processes, as they necessitate accessing multiple locations to understand dependencies. It highlights the advantages of local setups and discusses how AI coding agents have shifted the economics of repetition in writing tests. The author argues that while some help from abstractions is beneficial, each test should ultimately own its context for better clarity and maintainability.
Code example from the article:
setup docustomer = insert(:customer)product = insert(:product, price: 1_000)%{customer: customer, product: product}end
continue reading onryanzidago.com
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.