asp.net mvc 中的单元测试有问题吗?
更新:所以每当我拥有 HostType、AspNetDevelopmentServerHost、URLToTest
等所有元标记时,我都会收到错误。因此,当我评论这些标签时,我可以运行测试,但我需要这些标签才能使连接字符串可供控制器连接到数据库。 我通过右键单击 asp.net mvc 中的操作并说 创建单元测试..
创建了一个基本单元测试。我只是想运行一个基本单元测试。我收到此错误 -
测试适配器“WebHostAdapter”在运行测试“IndexTest”时引发异常。网站无法正确配置;获取 ASP.NET 进程信息失败。请求“http://localhost:55767/VSEnterpriseHelper.axd”返回错误:远程服务器返回错误:(500) 内部服务器错误。
这是我的方法 -
[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\Users\\Administrator\\Desktop\\MyWebsite\\Websites\\Customer1\\Customer1", "/")]
[UrlToTest("http://localhost:55767/Admin/Dashboard")]
public void IndexTest()
{
DashboardController target = new DashboardController(); // TODO: Initialize to an appropriate value
string id = string.Empty; // TODO: Initialize to an appropriate value
ActionResult expected = null; // TODO: Initialize to an appropriate value
ActionResult actual;
actual = target.Index(id);
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
知道这里会出现什么问题吗?我尝试用谷歌搜索,但没有找到解决我问题的好方法。我正在使用 VS2010 Ultimate 和 asp.net mvc 2.0。
UPDATE: SO I am getting the error whenever I have all meta tags like HostType,AspNetDevelopmentServerHost,URLToTest
. So when I comment these tags I can run the test but I need to have these tags to have the connection string available for controller to connect to database.
I created a basic unit test by just right clicking on the action in asp.net mvc and saying Create unit tests..
.I am just trying to run a basic unit test.I am getting this error -
The test adapter 'WebHostAdapter' threw an exception while running test 'IndexTest'. The web site could not be configured correctly; getting ASP.NET process information failed. Requesting 'http://localhost:55767/VSEnterpriseHelper.axd' returned an error: The remote server returned an error: (500) Internal Server Error.
This is my method -
[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\Users\\Administrator\\Desktop\\MyWebsite\\Websites\\Customer1\\Customer1", "/")]
[UrlToTest("http://localhost:55767/Admin/Dashboard")]
public void IndexTest()
{
DashboardController target = new DashboardController(); // TODO: Initialize to an appropriate value
string id = string.Empty; // TODO: Initialize to an appropriate value
ActionResult expected = null; // TODO: Initialize to an appropriate value
ActionResult actual;
actual = target.Index(id);
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
Any ideas what would be the problem here ? I tried to google but didnt get a good solution for my problem. I am using VS2010 Ultimate and asp.net mvc 2.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您在 ASP.NET Web 应用程序项目(MVC 使用的项目)上执行此操作时,Visual Studio 将生成大量内容垃圾,每次你想运行单个单元测试时都会尝试启动 Web 服务器。你不想要这个。
这里有两种可能性:
When you do this on an ASP.NET web application project (which is what MVC uses) Visual Studio will generate a ton of crap and will try to start the web server every time you want to run a single unit test. You don't want this.
Here are two possibilities: