120 likes | 270 Views
Moles Isolation Framework. TDD Process. TDD Process. Code. TDD Process. Code. The Known State. Can be accomplished by: Initializing or setting the properties and fields of the tested object Emulating external dependencies (mocking or stubbing). The Known State. Can be accomplished by:
E N D
TDD Process Code
TDD Process Code
The Known State • Can be accomplished by: • Initializing or setting the properties and fields of the tested object • Emulating external dependencies (mocking or stubbing)
The Known State • Can be accomplished by: • Initializing or setting the properties and fields of the tested object • Emulating external dependencies (mocking or stubbing): • Mock objects
The Known State • Can be accomplished by: • Initializing or setting the properties and fields of the tested object • Emulating external dependencies (mocking or stubbing): • Mock objects • Manually created classes • Mock framework (Rhino Mocks, Moq, TypeMock etc.)
Mock objects • They can stub only what they can override: • Interfaces • Abstract classes and/or methods • Virtual methods • They cannot stub: • Static methods or classes • Non virtual or sealed methods • Sealed classes • Classes that have not been designed for testing/mocking • Value types
Moles Isolation Framework • Initially a part of the PEX • Allows the replacing of any .NET method or property with a delegate • It supports: • Static methods • Non virtual methods • Value types (DateTime etc.)
Pros/cons • Pros • Any data type, method or property can be mocked • Allows creating unit tests where only integration tests would have been possible • Allows abstracting the system resources • Cons • High initialization time • Test assembly size can grow very quick • Stopping the test while debugging it will leave the host process running and will require to be terminated manually • Naming scheme can become very cumbersome and hard to read: MDateTime.TryCreateInt32Int32Int32Int32Int32Int32Int32DateTimeOut
Resources • Moles: http://research.microsoft.com/en-us/projects/moles/ • Presentation and demo project: • www.byteflux.me