Unit Test configuration for ASP.NET application

给你一囗甜甜゛ 提交于 2019-12-05 18:56:18

The exception message that you are getting doesn't sound like it's a unit test at all. Are you trying to run a Visual Studio Web Test suite instead?

For unit testing, you should simply be able to create instance of the business logic classes and test them without interference from the ASP.NET runtime.

In MsTest, that might look like this:

[TestMethod]
public void Test5()
{
    var sut = new Thing();
    var expectedResult = new object();
    sut.Bar = expectedResult;
    var actual = sut.Bar;
    Assert.AreEqual(expectedResult, actual);
}

(perhaps not the most exciting test, though...)

No ASP.NET specifics anywhere to be found.

This is best ensured if you place the business logic in a seperate library and ensure that it doesn't reference System.Web, etc.

patil

Set the attribute UrlToTest to the Url In test. Like:

[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\xx\\xx\\Documents\\Visual Studio 2010\\Projects\\xx\\xx", "/")]
[UrlToTest("http://localhost:xxx/examples.aspx")]
[DeploymentItem("examples.dll")]

Or Like Mark said, Get Rid of the
[HostType("ASP.NET")] [AspNetDevelopmentServerHost("C:\xx\xx\Documents\Visual Studio 2010\Projects\xx\xx", "/")] [UrlToTest("http://localhost:xxx/examples.aspx")] [DeploymentItem("examples.dll")] Was trying to use it in an MVC Project and it didnt pass until I got rid of it

Just check if you have added app.config to your test project and it has necessary settings from your web.config (from the WebService Project).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!