Skip to content
Fully dynamic mocking for Lua
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Fully dynamic mocking for Lua. Create mock objects with ease, teach them to return values and verify their invocations.


Creating and using mocks

Start by requiring mockagne and creating some local function references for better readability:

local mockagne = require "mockagne"

local when = mockagne.when
local any = mockagne.any
local verify = mockagne.verify

Then just create a mock instance for you:

t = mockagne.getMock()

Then you can invoke anything on the mock instance. Like:

Verifying calls to mocks

After your test has executed, you might be interested if a specific function on a mock was called. For example, to check if function foo() was call, you would simply say:


Same works with parameters:"bar")

Returning values from mocks

If you want a call to to return a value, you can teach the mock with:

print("bar"))   -- this will print "baz"

Otherwise calls to mock methods will return nil.

More examples

For more examples, refer to mockagne_spec.lua that comes with. It contains all unit tests used to exercise mockagnes all features.


Easiest way to install mockagne is through luarocks. Just run

luarocks install mockagne

For manual installation, just add mockagne.lua to your package.path.

More information

Mockagne is written by Janne Sinivirta and Marko Pukari. It was created to help with testing of our mobile games written in Lua.

Mockagne name is a cross between mock and champagne, like it's Java big brother mockito. We are great fans of mockito and mockagne is heavily based on mockito's DSL.

You can’t perform that action at this time.