在项目中,很多时候我们需要测试某个方法中的一个方法,那么我们可以构建那样的方法,直接调用,这时候需要一个测试类,在C#中有专门的测试类库,Microsoft.VisualStudio.TestTools.UnitTesting,直接引用就行,再在类上添加TestClass特性和方法上添加TestMethod。右击含有TestMethod的方法“调试测试”!即可
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;//必须
using Log4NetApply;
namespace log4net
{
[TestClass];//必须
public class UnitTest1
{
[TestMethod];//必须
public void TestMethod1()
{
//需要测试的方法,直接传值
LogInfoPatternConverter d = new LogInfoPatternConverter();
d.dd();
}
}
}