您可能还想看看Verde框架。在语义上,测试看起来与Steve Sanderson的MvcIntegrationTestFramework类似,主要区别在于Verde在实际IIS AppDomain的上下文中执行测试(通过基于浏览器的测试运行器),而不是通过程序创建的测试。这提供了一些优点:首先它是对实际应用程序配置,网络拓扑结构,安全设置等的更真实的仿真。其次,您可以将测试作为后期部署步骤自动运行,或者甚至可以自动运行测试生产中应用程序监视的一部分。下面是包含在GitHub上的源代码MvcMusicStore取试样为例佛得角测试:
[IntegrationTest]
public void Index_Load_ExpectedHtml()
{
// Get a product to load the details page for.
var album = storeDB.Albums
.Take(1)
.First();
using (var scope = new MvcExecutorScope("Store/Details/" + album.AlbumId))
{
Assert.AreEqual(200, scope.HttpContext.Response.StatusCode);
Assert.IsTrue(scope.Controller is StoreController);
Assert.AreEqual("Details", scope.Action);
var model = scope.Controller.ViewData.Model as Album;
Assert.IsNotNull(model);
Assert.AreEqual(album.AlbumId, model.AlbumId);
Assert.IsFalse(String.IsNullOrEmpty(scope.ResponseText));
// Load the ResponseText into an HtmlDocument
var html = new HtmlDocument();
html.LoadHtml(scope.ResponseText);
// Use ScrappySharp CSS selector to make assertions about the rendered HTML
Assert.AreEqual(album.Title, html.DocumentNode.CssSelect("#main h2").First().InnerText);
}
}
有一个NuGet包,这使得它很容易添加到您的MVC项目。
嗨,大家好,我设法让史蒂夫·桑德森的集成测试框架和运行。我不得不修改源代码,因为它与我的项目中的一些dll存在问题,并且不断出现异常,但它现在很好,并且是一个集成测试的优秀工具 – Matthew 2010-07-12 10:39:25