先上代码
namespace UnitTest { [TestClass] public class SystemInfoerviceTest { private Isys_systemInfoService service; [TestInitialize] public void Setup() { service = new sys_systemInfoService(); } [TestMethod] public void AddSystemInfo() { sys_systemInfo systemInfo = new sys_systemInfo { sys_Name = "测试系统", sys_memo = "系统备注" }; bool flag = service.AddSystemInfo(systemInfo); Assert.AreEqual(true,flag); } [TestMethod] public void LoadAllSystemInfo() { var result = service.LoadAllSystemInfo(); foreach(var item in result) { Console.WriteLine($"系统编号:{item.sys_id}{Environment.NewLine}" + $"系统名称:{item.sys_Name}{Environment.NewLine}" + $"系统描述:{item.sys_memo}{Environment.NewLine}"); } } } }
单元测试一般都是基于接口的,比如Isys_systemInfoService
TestInitialize初始化的时候执行的函数
TestMethod待测试的方法