(Quick Reference)

12.3 Mocking - Reference Documentation

Authors: Andres Almiray

Version: 1.2.0

Table of Contents

12.3 Mocking

Mocking is but one of the many alternatives you have at your disposal to reduce complexity while setting up a test that requires a good number of components to be setup before actually testing the real class under test. Griffon provides a few mocking helper methods and classes, which will be discussed next.

12.3.1 MockGriffonApplication

MockGriffonApplication is a fully functional GriffonApplication with the advantage that it lets you override the location of all configuration classes: Application, Builder, Config and Events.

If you choose to change the default UIThreadHandler then you must do it so right after the application has been instantiated and no other operation that requires multi-thread access has been called, otherwise you won't be able to change it's value.

By default, a MockGriffonApplication defines the following:

  • MockApplication - setups a 'mock' MVC group with 3 elements: MockModel, MockView and MockController
  • MockBuilderConfig - defines a single builder entry: griffon.test.mock.MockBuilder
  • MockConfig - defines a single config entry: mocked = true
  • MockEvents - defines an event handler for 'Mock'

The remaining classes have these settings:

  • MockBuilder - a single node named mock that returns a map with any properties that were defined on the node.
  • MockModel - a lone observable property value of type String.
  • MockView - simple script that calls the mock node defined by the builder.
  • MockController - a controller with no actions.