MoqIs designed and developed for. Net by leveraging the features of. Net 3.5, such as the LINQ Expression Tree and lambda expressions.Mocking Library. Its goal is to integrate mocking with existing unit tests in a natural way, making it simpler and more intuitive, to prevent developers from being forced to rewrite the testing or learning the mock framework that requires a large amount of recording/playback. The objective of Moq is to help write testsCodeBut does not use the mocking framework. Moq's design principle is to acquire good refactoring capabilities with a very low threshold.
Moq provides the following features:
- Strong type: it does not support setting expectation (expectations) using strings, nor does it support returning values and constraints of the object type.
- Perfect Integration with vs: all features fully support vs intelligent sensing, from setting expectations to specifying parameters and return values of referenced methods.
- You no longer need to learn about recording/playing. You only need to build your own mock, set your expectations, call it, and verify them selectively.
- As described in the first three features, this leaves its learning curve extremely low, and in most cases you don't even need to read the document.
- Fine-grained control is better than using a simple mockbehavior enumerator to implement mock for behavior (no longer need to learn the theoretical differences between mock, Stub, fake, and dynamic mock)
- Mock can be performed on interfaces and Classes
- Overload expectation: You can set the default expectation for the mock method during global settings. You can reload the mock method as needed.
- Input Construction parameters to the Mock class
- Use mock to intercept and trigger events
Moq isOpen SourceAnd look forward to more people's contributions, its source code,Binary PackageAndGetting startedAll are hosted on Google Code.
Daniel cazzulino is the main Maintainer of Moq. He has releasedA series of articlesTo illustrate why Moq is created, and provides several good examples to demonstrate how to use Moq effectively.
Connection: http://www.infoq.com/cn/news/2008/08/Moq