为什么当我在 VS2008 中运行单元测试时 cassini 会启动?

发布于 2024-07-28 23:44:37 字数 106 浏览 2 评论 0原文

我正在尝试测试一个不需要在 asp.net 环境中运行的类(控制器)。

但是当我运行测试时,卡西尼号启动了。

如何避免卡西尼号负载?

谢谢

I'm trying to test a class (a controller) that doesn't need to run inside the asp.net environment.

But when I run the test, cassini starts.

How can I avoid the cassini load?

Thanks

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

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

发布评论

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

评论(4

你的笑 2024-08-04 23:44:37

问题在于代码覆盖率。 我已禁用它,现在卡西尼不再启动(无需调试)。

The problem was the code coverage. I have disabled it and now cassini doesn't start anymore (without debugging).

晨与橙与城 2024-08-04 23:44:37

Cassini 应该仅在调试或运行项目时运行(即按 F5Ctrl-F5),而不是在执行单元测试时运行。 您可以通过查看 ASP.NET 项目的属性并选择 Web 选项卡来修改按 F5 时发生的情况。 您尚未指定如何执行测试,但 Visual Studio 单元测试框架和 NUnit 等框架都将在 Cassini 之外的单独进程中运行测试。 如果您使用自己的控制台应用程序项目来执行测试,则应确保已将此项目设置为 StartUp 项目。 然后按 F5 将执行您的测试控制台应用程序,而不是 Cassini。

Cassini should only run if you debug or run your project (i.e. by pressing F5 or Ctrl-F5), not when you execute your unit tests. You can modify what happens when you press F5 by viewing the properties for you ASP.NET project and selecting the Web tab. You haven't specified how you execute your tests, but both the Visual Studio unit testing framework and frameworks like NUnit will run your tests in a separate process that is not Cassini. If you instead have say your own console application project to execute your tests you should make sure that you have set this project as the StartUp project. Then pressing F5 will execute your test console application and not Cassini.

多像笑话 2024-08-04 23:44:37

如果您在调试模式下运行测试,cassini 将启动。 如果您在没有调试模式的情况下运行测试,则不会。

If you run your tests in debug mode cassini will start. If you run your tests without debug mode then it will not.

蒲公英的约定 2024-08-04 23:44:37

您的控制器确实需要 asp.net 环境,它是您的请求的处理程序。 您可以将 IDE 设置为使用 IIS。 单击项目的属性页,在 Web 选项卡上,您将看到“使用 IIS”单选按钮,该按钮可让您设置虚拟目录。 然后就没有卡西尼号了。

如果您使用了 Visual Studio 中的创建单元测试功能,那么它将进行如下测试

[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\working\\MDTest\\MvcApplication1", "/")]
[UrlToTest("http://localhost:1169/")]
public void AccountControllerConstructorTest()
{
   //Implementation
}

UrlToTest 属性是导致 cassini 启动的原因。 正如我上面所说,您的控制器确实需要 asp.net 环境,因为它是一个 http 处理程序,因此需要使用 http 来调用它才能测试它。 如果您只是不喜欢 cassini(这很公平),那么您仍然需要 IIS 才能让它工作。

如果您右键单击您的 Web 项目,然后按照本文顶部的说明进行操作,“创建单元测试”功能将生成此内容,

[TestMethod()]
[HostType("ASP.NET")]
[UrlToTest("http://localhost/MvcApplication1")]
public void AccountControllerConstructorTest()...

无需 cassini 即可运行:)

Your controller does need the asp.net environment, it is the handler for your requests. You can set your IDE to use IIS instead. Click on the properties page of your project and on the web tab you will see a Use IIS radio button which will let you set up a virtual directory. Then no more cassini.

If you have used the create unit tests feature in Visual Studio then it will have made a test like this

[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\working\\MDTest\\MvcApplication1", "/")]
[UrlToTest("http://localhost:1169/")]
public void AccountControllerConstructorTest()
{
   //Implementation
}

The UrlToTest attribute is what is causing cassini to start. As I stated above, your controller does need the asp.net environment because it is an http handler, so it needs to be invoked using http in order to test it. If you just don't like cassini (fair enough) then you are still going to need IIS to get it to work.

If you right click on your web project, then follow the instructions at the top of this post, the Create Unit Tests feature will produce this

[TestMethod()]
[HostType("ASP.NET")]
[UrlToTest("http://localhost/MvcApplication1")]
public void AccountControllerConstructorTest()...

Which runs without cassini :)

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