500错误运行Visual Studio ASP.NET单元测试

编程入门 行业动态 更新时间:2024-10-24 22:27:56
本文介绍了500错误运行Visual Studio ASP.NET单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的单元测试项目中具有以下方法:

I have the following method in my unit test project:

[TestMethod] [HostType("ASP.NET")] [UrlToTest("localhost:3418/Web/SysCoord/ChooseEPA.aspx")] [AspNetDevelopmentServerHost("%PathToWebRoot%")] public void TestMethod1() { Page page = TestContext.RequestedPage; Assert.IsTrue(false, "Test ran, at least."); }

我遇到此异常:

运行测试"TestMethod1"时,测试适配器"WebHostAdapter"引发异常.网站配置不正确;获取ASP.NET进程信息失败.请求' localhost:3418/SysCoord/VSEnterpriseHelper.axd '返回错误:远程服务器返回错误:(404)找不到. 远程服务器返回错误:(404)找不到.

The test adapter 'WebHostAdapter' threw an exception while running test 'TestMethod1'. The web site could not be configured correctly; getting ASP.NET process information failed. Requesting 'localhost:3418/SysCoord/VSEnterpriseHelper.axd' returned an error: The remote server returned an error: (404) Not Found. The remote server returned an error: (404) Not Found.

页面在浏览器中的URL上应能正常工作: localhost:3418/Web/SysCoord/ChooseEPA.aspx .

The page works as it should in a browser at the url: localhost:3418/Web/SysCoord/ChooseEPA.aspx.

此物理路径为:C:\ ESI \ HR_Connect2 \ BenefitChangeSystem \ Application_DEV \ Web \ SysCoord.

This physical path is: C:\ESI\HR_Connect2\BenefitChangeSystem\Application_DEV\Web\SysCoord.

任何想法都会受到赞赏.

Any ideas would be appreciated.

更新1

根据本文,以下内容已添加到我的web.config文件中.还使web.config可写并杀死/重新启动了开发Web服务器.行为没有变化.

Added the following to my web.config file per this article. Also made the web.config writable and killed/restarted the development web server. No change in behavior.

<location path="VSEnterpriseHelper.axd"> <system.web> <authorization> <allow users="*"/> </authorization> </system.web> </location>

更新2

将AspNetDevelopmentServerHost属性更改为与[AspNetDevelopmentServerHost(%PathToWebRoot%\ solutionfolder \ webfolder","/webfolder")]等效)可以解决404问题.

Changing the AspNetDevelopmentServerHost attribute to the equivalent of [AspNetDevelopmentServerHost("%PathToWebRoot%\solutionfolder\webfolder", "/webfolder")] resolved the 404 problem.

不幸的是,测试开始返回500错误.进步,但不多.一个干净项目的反复试验得出的结论是,对web.config中的自定义类的引用导致了此问题.

Unfortunately the test began to return a 500 error instead. Progress, but not much. Trial and error with a clean project led to the conclusion that references to custom classes in the of the web.config were causing the problem.

例如:

<profile enabled="true" defaultProvider="MyProfileProvider"> <providers> <add name="MyProfileProvider" connectionStringName="ProfileConnectionString" applicationName="/MyApp" type="System.Web.Profile.SqlProfileProvider"/> </providers> <properties> <add name="Theme" type="String" defaultValue="Default"/> <add name="LastLogon" type="DateTime"/> <add name="LastLogonIp" type="String"/> <!-- <add name="EmployeeSearchCriteria" type="MyApplicationFramework.Profile.EmployeeSearchCriteria"/> <add name="DocumentSearchCriteria" type="MyApplicationFramework.Profile.DocumentSearchCriteria"/> --> </properties> </profile>

使用上述条件类型进行注释后,测试运行良好.取消注释后,将返回500错误.

With the criteria types above commented out the test ran fine. With them uncommented, the 500 error was returned.

过去有人遇到过类似的问题吗?

Anyone had a similar problem in the past?

推荐答案

我以前遇到过这个问题,在阅读了所有我可以用google搜索的问题(包括该线程)之后,我就放弃了.

I've had this problem before and at that point gave up after reading all I could google about it (including this thread).

在我看来,该解决方案很简单.我要做的就是不使用ASP.NET测试属性,而只是将MVC项目作为DLL测试.

The solution turned out to be simple in my case. All I had to do was not use ASP.NET test attributes and simply test the MVC project as a DLL.

从测试中删除多余的属性.

Remove the extra attributes from the test.

[TestMethod] public void TestMethod1() { Page page = TestContext.RequestedPage; Assert.IsTrue(false, "Test ran, at least."); }

步骤2

在代码覆盖率"中,取消选中"MVC项目",然后手动添加MVC项目的DLL.

Step 2

In Code Coverage, uncheck the MVC Project and add the MVC Project's DLL manually.

Voila,它是作为常规程序集进行检测的,没有错误,不会启动Development Server,也不会使团队构建失败.

Voila, it get instrumented as a normal assembly, no errors, doesn't spin up the Development Server, also doesn't fail the Team Build.

更多推荐

500错误运行Visual Studio ASP.NET单元测试

本文发布于:2023-11-17 05:06:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608935.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   错误   Visual   NET   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!