[英]How to mock objects in C# using Visual Studio Unit Testing framework or NUnit framework?
I have moved to developing applications in C# from Java. 我已经开始从Java用C#开发应用程序。 I came across the Visual Studio unit testing framework provided by Visual Studio, and another framework called NUnit.
我遇到了Visual Studio提供的Visual Studio单元测试框架,以及另一个称为NUnit的框架。
I'm using Visual Studio Pro, so Microsoft Fakes is not applicable to me. 我使用的是Visual Studio Pro,因此Microsoft假货不适用于我。 Also, I came across moq, and rhinomocks but I'm not sure about these.
另外,我遇到了最小起订量和犀牛,但是我不确定这些。
There are three popular unit testing frameworks used to support unit testing (Microsft Microsoft.VisualStudio.TestTools
, NUnit
and xUnit
) and none of them supports mocking. 有三种流行的单元测试框架用于支持单元测试(Microsft
Microsoft.VisualStudio.TestTools
, NUnit
和xUnit
),但它们都不支持模拟。
From my experience, moq
works quite well for most projects. 根据我的经验,
moq
对于大多数项目都非常有效。 For the example of how to use it in practice check this project DjvuNet . 有关如何在实践中使用它的示例,请检查此项目DjvuNet 。 There you will find multiple examples of simple and complex mocking scenarios.
在那里,您将找到简单和复杂的模拟场景的多个示例。 This particular project uses xUnit as a unit test framework but it does not have any impact on how mocking is done.
这个特定的项目使用xUnit作为单元测试框架,但是它对模拟的完成方式没有任何影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.