Mock Interfaces & abstract classes
Interfaces or Abstract classes allows Mock framework to be able to create stubs, A stub is a small block of code that is replacement of another component or code block. TDD approach of R-G-R (Red-Green-Refactor) is an example where a stub might be useful. In order to make a test successfull (Green), you would need a stub for places where actual definition is either not written or unknown.Mock Everything in .NET
Able to mock everything in a class, such as- mock dependent objects
- non-virtual methods
- sealed classes
- static methods
- static classes
- non-public members
- non-public types
Mock Legacy Code
Assume some legacy code that has got some core business logic but has been designed/coded way before TDD has even started- no interfaces
- no abstract classes
- has dependencies
Auto Recursive Fakes
Once a mock is created some methods and properties will automatically return non null values such as interfaces, delegate, virtual class etc. This is also known as recursive mock.Fake Dependencies
If a mock is dependent on another object, framework should allow to either populate or assign dependency so as to make the test succeed. Most of the frameworks will support it by default.Unit Test Integration
Allow easy integration with unit test tools such as NUnit, MSTest, Xunit etc.Build Server Integration
Mock framework should allow you to be able to automate unit tests as part of your build & continuous integration. It should be able to support various build servers such as TFS, MSBuild, Nant, CruiseControl.NET etcCode coverage Integration
Mock framework should allow to be integrated with 3rd party code coverage so as to produce various metrics that can easily point out areas of code that has not been covered by a unit test or has been wrongly written. It should be able to support various 3rd party code coverage software such as NCover, MSTest Code Coverage, ReSharper etc.All of the these are only related to .net code. The mock framework features that are required for javascript mocking is out of scope of this article. The list of mock frameworks can be seen at Mock frameworks for .NET Part 2
Intelligence is the ability to adapt to change.
Stephen Hawking
0 comments:
Post a Comment