locked
Unit Test An ASP.NET *!* Website *!* RRS feed

  • Question

  • I have an ASP.NET framework 4.0 Visual Studio 2010 Website not Web Application.  I want to Unit Test my Website.

    I created a class file in my App_Code folder and then created a class library for my website.

    /// <summary>
            ///A test for xxxxx_UnitTest 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("directory", "/xxxxx_Test")]
            [UrlToTest(http://localhost/xxxxx_Test/Default.aspx)]
            public void xxxxx_UnitTestConstructorTest()
            {
                xxxxx_UnitTest_Accessor target = new xxxxx_UnitTest_Accessor();
                Assert.Inconclusive("TODO: Implement code to verify target");
            }

    But When I go to Debug and Run my Unit Test it gives me this 500 Internal Error Code ...

    Error	xxxxx_UnitTestConstructorTest	xxxxx_UnitTests	The test adapter 'WebHostAdapter' threw an exception while running test 'xxxxx_UnitTestConstructorTest'. The web site could not be configured correctly; getting ASP.NET process information failed. Requesting 'http://localhost:3535/xxxxx_Test/VSEnterpriseHelper.axd' returned an error: The remote server returned an error: (500) Internal Server Error.
    ...	

    Does anyone know how to fix this?  Thanks
    Monday, June 4, 2012 8:44 PM

Answers

  • Hi Chjones2008,

    Thank you for posting in the MSDN forum.

    Do you mean that you develop the Unit Tests for ASP.NET Web Services like this article?

    …Returned an error: The remote server returned an error: (500) Internal Server Error.

    Based on the error message, it seems that it is caused by the web site. Could you run the URL manually? Please check the Event Log to see if there any ASP.NET relating error message in Application node. For detailed information, see this similar thread “Ugly bug when running Unit test”.

    If you run your test in the Test View window, whether it has the same issue?

    In addition, I find an article about Debug while Running a Test in an ASP.NET Solution, if possible, you could check it, and hope it could provide useful information.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Chjones2008 Thursday, June 7, 2012 12:58 AM
    Wednesday, June 6, 2012 5:51 AM

All replies

  • Hi Chjones2008,

    Thank you for posting in the MSDN forum.

    Do you mean that you develop the Unit Tests for ASP.NET Web Services like this article?

    …Returned an error: The remote server returned an error: (500) Internal Server Error.

    Based on the error message, it seems that it is caused by the web site. Could you run the URL manually? Please check the Event Log to see if there any ASP.NET relating error message in Application node. For detailed information, see this similar thread “Ugly bug when running Unit test”.

    If you run your test in the Test View window, whether it has the same issue?

    In addition, I find an article about Debug while Running a Test in an ASP.NET Solution, if possible, you could check it, and hope it could provide useful information.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Chjones2008 Thursday, June 7, 2012 12:58 AM
    Wednesday, June 6, 2012 5:51 AM
  • Hi, Thanks for your reply. This issue was resolved not the most efficient way but its one method.

    Since, my website is not an application I dont have a .DLL to use so I can't extract my methods as I want to and I dont have an assembyInfo file to refer to so I copy my c# files over to my class library for reference where the unit testing gets done.  I have my constructor up top (top of this page) that calls the methods I want to test and pass the parameters over to that method and tests the methods accordingly. 

    Now, for what you said, Yes,  The statement UrlToTest, has to refer to an actual webpage in the project directory otherwise it throws the 500 Internal Error, after putting a valid Url in, that error went away.  Thanks for your input.

    Now, digging in furthur to Unit Testing on a website not an application.

    You might see an error message that says ...

    The web.config file for the site http://localhost:0/ contains information from a previous run.  Replacing it with the backup file (web.config.backup) should fix the issue.

    *To fix this issue.  You have to remove these lines from your web.config file first (Back to its original state before you ran the unit test)

    <appSettings>     
    <add key="microsoft.visualstudio.teamsystems.aspnetdevserver:/" value="3311;True;3204;1" />
    <add key="microsoft.visualstudio.teamsystems.backupinfo" value="1;web.config.backup" /> 
    </appSettings> 
    <runtime>     
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">     
    </assemblyBinding> 
    </runtime>

    *Make sure your web.config file is the only refrence to web.config in your project folder.  Make sure there are no files named web.config.backup in your project folder.

    That should fix the issue.

    If you are encrypting your web.config file.  Go to the backup web.config.backup file, copy it, paste it into your web.config file (restoring it to its original state).  Delete the backup file.  Then run and you should pass the unit test if everything else is ok. 


    • Edited by Chjones2008 Wednesday, June 6, 2012 7:43 PM
    Wednesday, June 6, 2012 7:42 PM