https://github.com/sheyll/erlymock
An EasyMock inspired mocking library for erlang.
https://github.com/sheyll/erlymock
Last synced: 20 days ago
JSON representation
An EasyMock inspired mocking library for erlang.
- Host: GitHub
- URL: https://github.com/sheyll/erlymock
- Owner: sheyll
- License: mit
- Created: 2011-02-07T16:43:41.000Z (about 15 years ago)
- Default Branch: 7.3.0-dev
- Last Pushed: 2023-03-28T14:54:57.000Z (almost 3 years ago)
- Last Synced: 2025-10-21T17:51:05.805Z (5 months ago)
- Language: Erlang
- Homepage: http://hexdocs.pm/em
- Size: 4.49 MB
- Stars: 23
- Watchers: 3
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Erlang Module Mocking
**Easy to use mocking library for unit testing**
* **[API Documentation](https://hexdocs.pm/em)**
* **[Rebar3 (hex) Installation](https://hex.pm/packages/em)**
## Example
`prouction.erl`:
find_and_read_book(Isbn) ->
{ok, Book} = library:lookup({isbn, Isbn}),
media:view_book(Book).
`production_test.erl`:
take_book_test() ->
Mock = em:new(),
ISBN = '978-3-596-17577-2',
%% expectations:
em:strict(Mock, library, lookup, [{isbn, ISBN}], {return, {ok, some_book_id}}).
em:strict(Mock, media, view_book, [some_book_id], {return, ok}),
em:replay(Mock),
%% Run code under test:
production:find_and_read_book(ISBN),
%% assertions:
em:verify(Mock).
## Installation
**Rebar3** and **[hex.pm](https://hex.pm/packages/em)** recommended.
Add this to your `rebar.config`:
{em, "7.2.6"}