1、新建mvc项目
添加controller
添加action 或者方法
public ActionResult Index(string str) { ViewBag.Teststr = str; return View("Details"); } public ActionResult Index2(string str) { ViewBag.Teststr = str; return View("Details2"); } public string Test(string str) { return "11"; } public string Test(MinimumDiscountHelper test) { return "11"; }
2、新建单元测试项目
引用
using Manager.Controllers;
using System.Web.Mvc;
添加测试方法
[TestClass] public class UnitTest { [TestMethod] public void TestMethod1() { var controller = new UnitController(); var result = controller.Index("2") as ViewResult; Assert.AreEqual("Details", result.ViewName); } [TestMethod] public void TestMethod2() { var controller = new UnitController(); var result = controller.Index2("3") as ViewResult; Assert.AreEqual("Details", result.ViewName); } [TestMethod] public void TestMethod3() { var controller = new UnitController(); var result = controller.Test("3"); Assert.AreEqual("11", result); } }
可选择批量测试(光标在类表层) 或者单一测试(光标在方法体)可设断点(调试测试)
借鉴http://www.uml.org.cn/Test/200912248.asp