Hi List,
I'm excited to announce Mockatoo (http://lib.haxe.org/p/mockatoo), a Haxe library for mocks creation, verification and stubbing that is loosely based on the public API of Mockito (a java mocking framework)
It uses Haxe macros to generated mock implementations of classes and interfaces for testing.
It has been thoroughly tested on Haxe 2.10 across most platforms (AVM2, JavaScript, Neko, C++, etc), and is designed to integrate seamlessly with munit and mcover
Source, examples, and documentation can be found on github (http://github.com/misprintt/mockatoo)
Main Features
Mock any class or interface (or typedef alias), including types with generics
var mockedClass = Mockatoo.mock(SomeClass);
var mockedInterface = Mockatoo.mock(SomeInterface);
var mockedClassWithGenerics = Mockatoo.mock(SomeList, [String]);
Verify a method has been called with specific paramaters
Mockatoo.verify(mock).foo();
Mockatoo.verify(mock).someMethod("foo", "bar");
Define a stub response when a method is invoked
Mockatoo.when(mock.foo("bar")).thenReturn("hello");
Mockatoo.when(mock.someMethod("foo", "bar").thenThrow(new Exception(""));
Define Custom argument matchers and wildcards
Mockatoo.when(mock.foo(anyString)).thenReturn("hello");
Mockatoo.when(mock.foo(isNull)).thenReturn("world");
Verifying exact number of invocations
Mockatoo.verify(mock, times(2)).foo();
Mockatoo.verify(mock, atLeast(2)).foo();
Mockatoo.verify(mock, atLeastOnce).foo();
Mockatoo.verify(mock, never).foo();
More documentation here: https://github.com/misprintt/mockatoo
---
Merry mocking,
Dom
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
I've just released Mockatoo 1.3.0 to Haxelib.
It provides a simplified, smarter, macro enhanced API when using Haxe’s ‘using’ mixin (and is still fully backwards compatible with existing API).
using mockatoo.Mockatoo;
...
var mock = SomeClass.mock();
var mock = SomeInterface.mock();
var spy = SomeClass.spy(); // partial mock that calls real methods unless stubbedNew macros have been added for simplified stubbing with ‘using’:
mock.someMethod().returns("foo");
mock.someMethod("foo").throws("some error");
mock.someMethod("bar").calls(function(args){return "bar";});
mock.someMethod().callsRealMethod();
mock.someMethod().stub(); // resets to default stub value (i.e. null)You can allso stub properties and getter setters (since 1.2.0)
mock.someProperty.returns("some value");Verifications now also support raw integer counts
mock.someMethod().verify(1); //converted to verify(times(1))Verfifying and stubbing mock fields are now validated at compile time to prevent runtime exceptions caused by out of date field references.
mock.someMethodThatDoesNotExist().verify(); //causes compilation errorThe syntax for wildcard Matchers has been updated to be compiler-safe when using ‘using’
mock.someMethod(Mockatoo.anyString()).returns("foo");For more information refer to the updated documentation , developer guide and examples on github.
Cheers,
Dom
--