user509685
user509685

Reputation: 55

Unit Testing for Websites or Webforms or .Aspx page: code coverage

I have one website which was made in Asp.Net. I want to have the code coverage for the website now.

Can anybody suggest me which are the possible ways to have the code coverage for the website? Suggestions on how to write unit test methods for Webform or .Aspx page are also welcome.

Upvotes: 1

Views: 334

Answers (1)

Jeetu
Jeetu

Reputation: 156

Try following steps to enable code coverage:
- Open the local.testsettings which you can access from Test -> Edit Test Settings -> Local (local.testsettings)
- List item Select Data and Diagnostics from the list
- Select the Enabled checkbox on the Code Coverage row
- Double-click the Code Coverage row
- Select the assemblies you want to instrument
- Specify a re-signing key file if your assemblies are strong-named
- Click OK
- Click Apply
- Click Close
For unit test you can have seperate class library project in the same solution where you can create unit test method. For example :

/// <summary>
    /// Holds test for MapRoles.
    /// </summary>
    [TestClass]
    public class MapRolesTest
    {
        /// <summary>
        /// Perform test on CompareUserRoles.
        /// </summary>
        [TestMethod]
        public void CompareUserRolesTest()
        {
            //// The class which is inside actual asp.net web application.
            MapRoles objMapRoles = new MapRoles();

            //// Get role of the user1.
            string user1Role = objMapRoles.GetUserRole("Jeet");

            //// Get role of the user2.
            string user2Role = objMapRoles.GetUserRole("Vishwajeet");

            //// Assert.
            Assert.AreEqual(user1Role, user2Role);
        }
}

Upvotes: 1

Related Questions