A personal guide to writing readable and maintainable Elixir tests using ExUnit. Key practices include: using a @subject module attribute to clearly identify the module under test, grouping tests with describe blocks named after functions, avoiding module mocking in favor of dependency injection via function arguments, skipping ex_machina factories in favor of direct application context calls, and leveraging property-based testing for broader input coverage. The author strongly advocates against mocking libraries as they prevent async test execution.
Table of contents
@subject module attribute for module under test #describe with function name #Avoid module mocking #Avoid ex_machina factories #Property testing is awesome #Parting words #Sort: