本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 在编写单元测试时,我们会遇到不同的外部依赖项,大体上可以分为两类: 依赖于接口或抽象类 依赖于具体类 我们将使用 Microsoft Fakes 分别对两种条件下的依赖项进行隔离. 依赖于接口或抽象类 首先,我们来定义被测试代码. public interface IEmailSender { bool SendEmail(string content); } public class Custo
Shim类中无法找到参数包含CancellationTokenSource的方法,这句话有点绕口,看例子. 一.代码 public class CancellationDemo { public int DoSomething(CancellationTokenSource cts) { if (cts.IsCancellationRequested) { ; } else { ; } } } DoSomething这个方法的参数包含CancellationTokenSource. 二.问题 但
Prevent and troubleshoot runtime issues Troubleshooting performance, security and errors using performance wizard (Vs2012) Using VS profiler (Analyzer | Profiler) Using Performance Monitor NLog/log4net for logging Tracing, Trace.WriteLine("Message&qu
stub常用于虚拟接口.类.方法,无法重写静态方法(stub需要传递到具体调用代码中) shim常用于重写静态方法(在ShimsContext.Create()作用域内,拦截Runtime动态修改方法的实现,静态方法无需传递) shim如果用于重写非静态方法,依然需要传递 以下两种的目的都是虚拟TokenHandler.GetToken这个方法 stub: var stubTokenHandler = new StubTokenHandler<Token>("user")
如题,本文主要作为在VS2012使用Fakes的入门示例,开发工具必须是VS2012或更高版本. 关于Fakes的MSDN地址:http://msdn.microsoft.com/en-us/library/hh549175.aspx 关于VS2012单元测试的前期文章: 1.<在Visual Studio 2012使用单元测试>. 2.<VS2012 单元测试之泛型类(Generics Unit Test)>. 3.<VS2012 Unit Test —— 我对接口进行单元