Using External Mocking Frameworks

MXUnit comes bundled with its own lightweight, yet full-featured mocking framework. If you would prefer to use an external mocking framework and still take advantage of MXUnit's mock() method, you can tell MXUnit to use a different framework. You can do this in a number of ways.

Use the setMockingFramework() Method

In your test case you can call the setMockingFramework() method, passing in the name of the framework you wish to use. MXUnit will then use that framework for any calls to mock(). For example:

Setting a Default Mocking Framework for a Test Case
Change the Default Mocking Framework in mxunit-config.xml

MXUnit ships with a config file, named mxunit-config.xml, that resides in the framework folder. There is a config-element in this file with a type of mockingFramework, which is set to MightyMock (the name of the built-in mocking framework) by default. If you change this value to the name of another supported framework, MXUnit will use that framework by default instead.

Pass a Mocking Framework Name into the mock() Method

You can use the third argument of the mock() method, to override the framework to use. For example:

Mocking with a Different Framework
Mocking Frameworks Supported

MXUnit currently supports the MockBox and ColdMock mocking frameworks, in addition to its own. Additional frameworks can be supported by adding the required entries to the mxunit-config.xml file.

Labels

mocking mocking Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.