Mocks
UquoniTest has its own mock framework. This allows you to specify at run time what a method in a mock object should do. This could be:
- checking if the arguments satisfy a certain condition
- return a value
- throw an exception
- check how often it is called (optionally with upper and lower limits)
- assign values to reference or pointer arguments
- store arguments in a vector to examine later
- check whether it is called from only one thread at a time
You can also put these in a sequence object, that will perform the next action in it every time it is called. You can also select an action depending on the arguments with a Switch object.
Checking arguments is made easy with ArgsAre and ArgsEqual. In both of these you can ignore certain arguments by supplying Any().
uqtTEST(TestUseBase) { Mock mock; mock.m_mock_foo.SetAction( uqtMOCK_ASSERT(ArgsEqual(5, "hello", Any())) ); mock.m_mock_bar.SetAction( uqtMOCK_CASSERT(ArgsAre(EqualTo(1), Any(), LessThan(10))) ); UseBase useBase(&mock); ... }
On top of this you can check afterwards on which threads a method was called, and by which objects in what order if they are connected to a MockCallOrder object.