3

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");
        }
Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
Asad
  • 21,468
  • 17
  • 69
  • 94
  • what unit testing framework are you using? – Adam Pope Jan 12 '10 at 20:23
  • The one provided with VS2008 by Microsoft, "Microsoft.VisualStudio.QualityTools.UnitTestFramework" – Asad Jan 12 '10 at 21:37
  • @asdi: Despite what MS may call it, that's not a unit test. I re-tagged your question to draw in a slightly different audience that may be able to help you with this. – Mark Seemann Jan 12 '10 at 21:46

4 Answers4

5

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
  • 225,310
  • 48
  • 427
  • 736
  • 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 Jan 12 '10 at 21:44
  • 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 Jan 12 '10 at 21:53
  • 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 Jan 12 '10 at 22:00
  • 1
    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 Jan 12 '10 at 22:06
  • Thanks, getting along well with Moq – Asad Jan 15 '10 at 10:08
2

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")]
Jehof
  • 34,674
  • 10
  • 123
  • 155
patil
  • 127
  • 1
  • 7
1

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

Ody
  • 2,012
  • 4
  • 25
  • 35
0

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