Add support to change the default behavior #33

wants to merge 1 commit into


None yet

2 participants

salfab commented Nov 2, 2012

Right now, the default behavior cannot be changed. Instead, it must be specified for every single mock instantiation.

When a team chooses to work only with Strict behavior, it has no other options than explicitly calling the constructor by specifying that the behavior to use is Strict.

Since this can be error prone and time consuming, it would be ideal to set once and for all the default behavior to use for every subsequent mock instantiation.

This pull request contains a fix which will address this issue, while still retaining the current behavior.

The pull request also contains the tests defining the new specifications for the mechanism introduced.

@salfab salfab Add support to change the default behavior
 - All Mocks instantiated after setting the DefaultBehavior property will follow the new behavior if not mentioned explicitly, instead of always using the loose behavior.
- Unit tested.
kzu commented Feb 28, 2013

This is very weird. It's very much unclear which is the entry point for a test run that would uniquely be responsible for setting this default behavior. There's no "Main" for test runners. Any test fixture could change this value at will and the runtime behavior would be highly random if two fixtures set the default to a different value, where the tests could run multi-threaded.

The proper (current) way to specify defaults is to use a singleton MockFactory to create mocks. This would ensure they all have the same default behaviors. Much clearer (I think) than setting a global enum value... (since factory creation is very explicit, and scoping too)

@kzu kzu closed this Apr 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment