Вопрос

This is my first test for Asp.Net Web Application. We have an Engine consisting of several modules. I need to test classes in Engine Module. Though these clases are part of Asp.Net App, they consists of only business logic.

How can I test these classes in isolation other being part of WebApp ? because i am getting this error

The Web request 'http://localhost:8936/' completed successfully without running the test. This can occur when configuring the Web application for testing fails (an ASP.NET server error occurs when processing the request), or when no ASP.NET page is executed (the URL may point to an HTML page, a Web service, or a directory listing). Running tests in ASP.NET requires the URL to resolve to an ASP.NET page and for the page to execute properly up to the Load event. The response from the request is stored in the file 'WebRequestResponse_BlogManagerBPOConstr.html' with the test results; typically this file can be opened with a Web browser to view its contents.

Thanks

EDIT: @Mark, this is one of the TestMethods generated by designer

/

// <summary>
        ///A test for BlogManagerBPO Constructor
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("D:\\WorkingCopies\\MyProject\\Engine", "/")]
        [UrlToTest("http://localhost:8936/")]
        public void BlogManagerBPOConstructorTest()
        {
            BlogManagerBPO target = new BlogManagerBPO();
            Assert.Inconclusive("TODO: Implement code to verify target");
        }
Это было полезно?

Решение

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.

Другие советы

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).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top