talira

Mocking library for Erlang

open sourceApache-2.0free

meck replaces Erlang modules with mocks for tests. Expectations are added, merged and deleted at runtime, with argument matchers, sequences and loops of return values, passthrough to the original module and exceptions marked as intended. It keeps a full call history (calls, return values, exceptions and captured arguments), can wait for a call with a timeout, refuses to mock modules that don't exist unless told to, unloads mocks when the process that made them crashes, and can mock sticky modules and keep cover data. Install it from Hex as meck.

Problems it solves

  • replace an Erlang module with a fake in my unit tests
  • check which arguments a function was called with in an Erlang test
  • stub a dependency module's functions during EUnit or Common Test runs

Features

  • dynamic expectations added and removed at runtime
  • argument matchers, return sequences and loops
  • passthrough to the original module
  • full call history with captured arguments
  • wait for a call with a timeout
  • automatic unload when the creating process crashes
  • mocking of sticky modules
  • cover data backup and restore