带有 ASP.NET 网站的 NUnit
我目前正在尝试升级我们工作中的构建服务器,从没有构建服务器到拥有一个!
我正在使用 JetBrains 的 TeamCity (已使用 ReSharper 几年了,我信任他们的东西),并打算使用 NUnit 和 MSBuild。
但是,我遇到了一个问题:似乎无法使用 NUnit 测试 ASP.NET 网站。我原以为可以将其配置为在构建后测试 App_Code,但似乎很好地进行测试的唯一方法是将网站转换为 Web 应用程序(我的老板不喜欢这个想法)。
我该怎么办呢?
请记住,测试需要能够从 TeamCity 自动触发。
I'm currently trying to upgrade our build server at work, going from having no build server to having one!
I'm using JetBrains' TeamCity (having used ReSharper for a couple of years I trust their stuff), and intend to use NUnit and MSBuild.
However, I've come up with an issue: it appears that it is not possible to test an ASP.NET web site with NUnit. I had assumed it would be possible to configure it to test App_Code after a build, however it seems that the only way to do tests nicely is through converting the web site to a web application (which my boss does not like the idea of).
How could I go about this?
Please bear in mind that the testing needs to be able to be fired automatically from TeamCity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想对您的网站进行冒烟测试,或对某些端点进行攻击 - 请参阅下面的代码。
如果
另一方面,如果您想测试不可测试(可憎)的 ASP.NET 网站程序集(而不是 Web 应用程序),正如法国人所说,SOL
程序集是一个随机命名的动态编译程序集框架临时 ASP.NET 文件的数量,使得测试几乎不可能。
您确实需要考虑几个选项:
抱歉,我认为您不会找到您想要的东西,但我可能是错的。让我们来看看。
祝你好运
下载带有站点和应用程序的 Visual Studio 2008 示例。
我为
WebHost.WebServer.dll
编写了一个包装器,它是开发服务器的核心,在 CI。我一直用它。这是一个缩小版本,包括使用示例。
Test.cs
WebHostServer.cs
注意:
Microsoft.VisualStudio.WebHost
命名空间包含在文件WebDev.WebHost.dll< 中/代码>。此文件位于 GAC 中,但无法从 Visual Studio 中添加对此程序集的引用。
要添加引用,您需要在文本编辑器中打开 .csproj 文件并手动添加引用。
查找包含项目引用的
ItemGroup
并添加以下元素:引用:http://www.codeproject.com/KB/aspnet/test-with-vs-devserver-2.aspx
If you want to smoke test your site, or bang on some endpoints - see the code below.
If, on the other hand, you want to test the untestable (detestable) ASP.NET website assembly (as opposed to a web app), you are, as they say in France, S.O.L.
The assembly is a randomly named dynamically compiled assembly deep in the bowels of the framework temporary ASP.NET files, making testing close to impossible.
You really do need to consider a couple of options:
Sorry, I don't think that you will find what you are looking for, but I could be wrong. Let's see.
Good Luck
Download Visual Studio 2008 sample with site and applicatgion.
I wrote a wrapper for
WebHost.WebServer.dll
which is the core of the development server that works quite well in CI. I use it all the time.Here is a scaled down version including a usage example.
Test.cs
WebHostServer.cs
NOTE: The
Microsoft.VisualStudio.WebHost
namespace is contained in the fileWebDev.WebHost.dll
. This file is in the GAC, but it is not possible to add a reference to this assembly from within Visual Studio.To add a reference you will need to open your .csproj file in a text editor and add the reference manually.
Look for the
ItemGroup
that contains the project references and add the following element:Reference: http://www.codeproject.com/KB/aspnet/test-with-vs-devserver-2.aspx