MXUnit's mocking integration allows you to create a mock with a single method call from within your test case, using the mock() method.
The fastest way to create a mock is to call mock() with no arguments:
If the component under test (CUT) expects the object that you are mocking to be of a specific type, you can create a type-safe mock:
That code will generate a mock that ColdFusion will recognize as being an instance of my.component.toBeMocked. Note that if the framework cannot create an instance of that object an exception will be thrown.
If you already have an instance of an object, and want to turn it into a mock, you can simply pass the instance of the object into the mock() method, which will create a type-safe mock:
If you wish to create a mock using a framework other than MXUnit's built-in mocking framework, you can pass a third argument to the mock() method, specifying the framework's name:
That will generate a mock using the MockBox framework. Currently MockBox and ColdMock are supported as external mocking frameworks, but others can be plugged in by editing the mxunit-config.xml file in the framework folder.
For more information on using external mocking frameworks with MXUnit, including how to specify a global mocking framework (instead of having to pass the framework name into the mock() call), see the Using External Mocking Frameworks section.
Once you've created a mock you'll want to define the behaviour of the mock.