有人用过 Steve Sanderson 的 MvcIntegrationTestFramework 吗?

发布于 2024-07-30 13:03:00 字数 241 浏览 11 评论 0原文

我正在寻找测试 ASP.NET MVC 应用程序的其他方法,并遇到了 Steve Sanderson 的 MvcIntegrationTestFramework. 这种方法看起来很有前途,但我想知道是否有人有任何实际经验可以分享。

I was looking into additional ways to test ASP.NET MVC applications and ran into Steve Sanderson’s MvcIntegrationTestFramework. The approach looks rather promising but I was wondering if anyone had any actual experience to share.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

智商已欠费 2024-08-06 13:03:00

我从中得到了一些非常好的结果。 我不在乎这里的其他人怎么说需要测试视图,一旦您将第一行代码添加到视图中,即使代码严格与表示相关,您也会引入潜在的错误,其中编写自动化测试是个好主意。 我的主要兴趣是捕获尽可能多的白屏和黄屏异常/错误。 为此,我一直在使用 Steven 的介绍性博客文章中的片段来确保页面正确呈现,而不会引发任何异常:

Assert.IsTrue(result.ResponseText.Contains("<!DOCTYPE html"));

我在这个框架中看到的小陷阱可能是:

  • 如果您的网站正在执行一些相当复杂的模型绑定视图和操作方法,您可能会发现自己创建了一些相当大的 NameValueCollections,例如本示例(实际上采用 LogonModel 视图模型对象的操作方法),因为我看不到任何传递任何复杂视图模型对象类型的方法使用此框架进入您的操作方法:

var result =浏览Session.ProcessRequest("/account/logon", HttpVerbs.Post, new NameValueCollection
{
{"用户名","我的名字"},
{"密码", "我的密码"},
{“returnUrl”,“/home/myActionMethod”}
});

  • 执行浏览Session.ProcessRequest("url") 创建一个应用程序主机/上下文,它实际上使用您正在测试的项目中的配置执行您正在测试的Web 代码。 这意味着测试运行得有点慢,并且可能会修改真实数据,因为我没有看到一种快速、简单的方法可以使用内置的任何工具将测试中的 Web 项目中的数据访问存储库替换为假版本测试框架。 换句话说,您可能需要使用一些基于 web.config 的方法来推出自己的。

I'm having some really good results from it. I don't care what anyone else on here says about the need to test views, as soon as you add your first line of code to a view, even if the code is strictly presentation-related, you introduce a potential for errors for which it would be a good idea to write automated tests. My primary interest is just to catch as many white screen and yellow screen exception/errors as possible. To do so I have been using the snippet from Steven's introductory blog post to ensure that the page rendered properly without throwing any exceptions:

Assert.IsTrue(result.ResponseText.Contains("<!DOCTYPE html"));

The small pitfalls that I see with this framework might be:

  • If your web site is doing some pretty complex model binding between the views and action methods, you might find yourself creating some pretty large NameValueCollections such as in this example (an action method which actually takes a LogonModel view model object), since I don't see any way of passing any complex view model object types into your action methods by using this framework:

var result = browsingSession.ProcessRequest("/account/logon", HttpVerbs.Post, new NameValueCollection
{
{"UserName","myName"},
{"Password", "myPassword"},
{"returnUrl", "/home/myActionMethod"}
});

  • Executing browsingSession.ProcessRequest("url") creates an application host/context which actually executes the web code that you are testing using the configuration in the project which you are testing. This means the tests run a bit slowly, and could possibly modify real data, since I don't see a quick and easy way of swapping out your data access repositories in your web project under test with fake versions by using any facility built into this test framework. In other words, you'd probably need to roll your own using some web.config-based means.
寄居者 2024-08-06 13:03:00

不久前阅读了 ardave 的回答后,我们实际上自己去尝试一下我们的新 Orchard 基于应用程序 Marinas.info。

首先,我建议任何人从此版本的分支开始,因为它更容易设置比原来的。

对于任何“普通”MVC3 应用程序来说,它都可以正常工作。 不幸的是,与 Orchard 一起使用时效果不佳,至少与未经修改的 Global.asax.cs 版本一起使用时效果不佳。 所以我们仍然继续 基于浏览器的测试之路,但我们继续使用它在内部执行 Orchard 命令该应用程序足够快。

After reading ardave's answer a while ago, we actually went to try it out for ourselves for our new Orchard based application Marinas.info.

First of all, I recommend anyone to start from a fork of this version as it's even easier to set up than the original.

For any "normal" MVC3 app it simply works. Unfortunately, together with Orchard it didn't play well, at least not with an unmodified version of their Global.asax.cs. So we still went down the browser based testing road but we keep using it to execute Orchard commands inside the app which is fast enough.

倾城月光淡如水﹏ 2024-08-06 13:03:00

我没用过这个框架。 但根据我阅读他的书的经验 -Pro ASP.NET MVC Framework ,以及他开发的另一个验证框架 xVal,我会说“他很棒”。

I haven't used this framework. But based on my experience of reading his book -Pro ASP.NET MVC Framework, and another validation framework xVal he developed, I would say "HE IS GREAT".

ゝ偶尔ゞ 2024-08-06 13:03:00

稍微尝试一下,它在某些情况下可能非常有用。 普遍竖起大拇指,如果我看到进一步的工作,我将在未来的项目中使用。

没有继续进行,因为已经有 WatIn 设置并处理了一些我不想再次处理的事情在这个框架内。 例如,通过对话框进行身份验证,这可能需要更改代码。

Experimented with it a little and it could be very useful in some situations. General thumbs up and if I saw further work on it I would use on a future project.

Didn't proceed as already have WatIn setup and taking care of some things I wouldn't like to tackle again in this framework. E.g. authentication through a dialog, which would probably require a code change.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文