views:

445

answers:

2

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");
        }
+1  A: 

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.

Mark Seemann
I have written tests manually, using NUnit and was able to run successfully using external NUnit IDE. I was trying to make use / practice "UnitTestFramework" and integrated , built-in test environment provided by Microsoft in VS2008.
Asad Butt
If you want to write tests NUnit-style, you can do so too with MSTest. Just don't use all their crappy wizards, but just create a new Test Project and start adding new Unit Tests to the project.
Mark Seemann
One more thing, I am using "Assertions" in NUnit at the moment. I do need "Mock" Objects for many mathods to be tested. How can I create Mocks ?
Asad Butt
Take a look here: http://stackoverflow.com/questions/1718463/what-are-the-real-world-pros-and-cons-of-each-of-the-major-mocking-frameworks/1720654#1720654
Mark Seemann
Thanks, getting along well with Moq
Asad Butt
A: 

I am getting the same error as above and really need to test the entire method even through the layers. Does anyone know how to get around this error? I have added a default.aspx page and it still does not work. I am on 2008 sp1 using the hello world sample of a web service to make sure I get this right.

Don Sweitzer
Add a question and reference this one.
Castrohenge