moq.NET 测试库
一个流行、友好的 .NET 模拟库
Moq(发音为“Mock you”或“Mock”)是.NET中唯一一个完全利用 .NET Linq 表达式树和 lambda 表达式而从头开发的模拟库,这使它成为最高效、类型安全和重构友好的模拟库。它支持模拟接口和类。它的API非常简单和直接,不需要任何关于模拟概念的知识或经验。
示例代码:
var mock = new Mock<ILoveThisFramework>(); // WOW! No record/replay weirdness?! :) mock.Setup(framework => framework.DownloadExists("2.0.0.0")) .Returns(true) .AtMostOnce(); // Hand mock.Object as a collaborator and exercise it, // like calling methods on it... ILoveThisFramework lovable = mock.Object; bool download = lovable.DownloadExists("2.0.0.0"); // Verify that the given method was indeed called with the expected value mock.Verify(framework => framework.DownloadExists("2.0.0.0"));
评论