Friday, November 20, 2009

Use interfaces for your injected models to ease testing

We use IoC to inject our models into the presentation models. When we test a presentation model we inject the models manually in the setUp method. Some models need things to be injected as well. This can make the setup quite complicated. To avoid this complexity it is very helpful if your model properties are typed as interfaces, e.g.

[Inject]
public var myModel : ISomeModel;

This gives you the possibility to replace the model with your own mock implementation of the interface. Typically your mock implementation does not use nested models. So the setUp of this mock model is much easier than setting up the original. This is especially true if you need to inject things, which are unrelated to your test, but are needed by the original model to work at all.

No comments:

Post a Comment