C# 我如何进行单元测试?

C# 我如何进行单元测试?,c#,.net,unit-testing,C#,.net,Unit Testing,我正在使用Mono和Lokad质量库开发一个API,它可以检查方法的特性,看看它们是否抛出异常,等等 我在这个API中的一个方法如下所示: // Get all methods which have a NotImplementedException var throwingMethods = _codebase.Methods .Where(m => m.GetInstructions() .Exists(i => i.Creates<

我正在使用Mono和Lokad质量库开发一个API,它可以检查方法的特性,看看它们是否抛出异常,等等

我在这个API中的一个方法如下所示:

// Get all methods which have a NotImplementedException
var throwingMethods = _codebase.Methods
    .Where(m => m.GetInstructions()
                 .Exists(i => i.Creates<NotImplementedException>())
    ).ToArray();
 return throwingMethods;
//获取所有具有NotImplementedException的方法
var throwingMethods=\u codebase.Methods
.Where(m=>m.GetInstructions()
.Exists(i=>i.Creates())
).ToArray();
返回方法;
我如何进行单元测试?C#本身没有做同样事情的能力。也许我只需要一个小集合,制作一个硬编码的集合,然后进行比较


谢谢

您可以尝试模拟
\u codebase
变量,为单元测试返回一些预定义的方法

如果
\u codebase
是由传递给您正在测试的类的构造函数的变量设置的(构造函数注入),那么这可能非常简单(当然,假设
方法
属性是可重写的,并且类没有密封)