2
我對asp.net mvc3應用程序的UnitTests有點問題。爲什麼單元測試使用mstest命令行失敗,但不在VS2010 Professional中?
如果我在Visual Studio 2010 專業版中運行一些單元測試,它們已成功通過。
如果我使用Visual Studio 2010專業版命令行
mstest /testcontainer:MyDLL.dll /detail:errormessage /resultsfile:"D:\A Folder\res.trx"
然後發生錯誤:
[errormessage] = Test method MyDLL.AController.IndexTest threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.
和我的控制器:
public ActionResult Index(){
RedirectToAction("AnotherView");
}
,並在測試
AController myController = new AController();
var result = (RedirectToRouteResult)myController.Index();
Assert.AreEqual("AnotherView", result.RouteValues["action"]);
如何解決此問題在兩種情況下都能正常工作(VS2010和mstest.exe)?
謝謝
PS:我讀Test run errors with MSTest in VS2010但如果我有VS2010旗艦版/高級版可能會解決。