Testing is an essential aspect of any programming language. Testing for ASP.Net applications
is possible with the help of Visual Studio.
Visual Studio is used to create test code. It is also used to run the test code for an ASP.Net
application. In this way, it becomes simple to check for any errors in an ASP.Net application.
In Visual Studio, the testing module comes with an out of box functionality. One can
straightaway perform a test for an ASP.Net project.
In this tutorial, you will learn
Introduction to testing for ASP.Net
Creating a .NET Unit Testing Project
Running the Test Project
Introduction to testing for ASP.Net
The first level of testing an ASP.Net project is unit level testing. This test is the functionality of an
application. The testing is conducted to ensure that the application behaves as expected. In
ASP.Net, the first task is to create a test project in Visual Studio. The test project will contain the
necessary code to test the application.
Let's consider the below web page. In the page, we have the message "Guru99 – ASP.Net"
displayed. Now how can we confirm that the correct message is displayed when an ASP.Net
project runs. This is done by adding a test project to the ASP.Net solution (used to develop web-
based applications). This test project would ensure that the right message is displayed to the user.
Let's look into more detail now and see how we can work on testing in ASP.Net.
Lab Objectives
After completing this lab, students will gain practical experience with:
Creating a .NET Unit Testing Project
Running the Test Project
Unit Testing
This study source was downloaded by 100000825543056 in Asp.Net:onComplete
from CourseHero.com 06-12-2022Tutorial 8.1-1
05:12:31 GMT -05:00
https://www.coursehero.com/file/94204528/Lab-81-Unit-Testing-in-AspNet-Complete-Tutorial-240119-HAdoc/
, Lab Procedures
A. Creating a .NET Unit Testing Project
Before we create a test project, we need to perform the below high-level steps.
1. Use our 'DemoApplication' used in the earlier sections. This will be our application
which needs to be tested.
2. We will add a new class to the DemoApplication. This class will contain a string
called 'Guru99 – ASP.Net.' This string will be tested in our testing project.
3. Finally, we will create a testing project. This is used to test the ASP.Net application.
So let's follow the above high-level steps and see how to implement testing.
Step 1) Ensure the DemoApplication is open in Visual Studio.
Step 2) Let's now add a new class to the DemoApplication. This class will contain a
string called 'Guru99 – ASP.Net.' This string will be tested in our testing project.
Follow below step to add a new class.
1. In Visual Studio, right-click the 'DemoApplication' in the Solution Explorer.
2. Choose the option Add Class from the context menu.
Step 3) In this step,
1. Give a name 'Tutorial.cs' for the new class.
2. Click the 'Add' button to add the file to the DemoApplication.
Now, a new class is added to file "DemoApplication."
Step 4) Open the new Tutorial.cs file from "DemoApplication". Add the string "Guru99
– ASP.Net."
Unit Testing
This study source was downloaded by 100000825543056 in Asp.Net:onComplete
from CourseHero.com 06-12-2022Tutorial 8.1-2
05:12:31 GMT -05:00
https://www.coursehero.com/file/94204528/Lab-81-Unit-Testing-in-AspNet-Complete-Tutorial-240119-HAdoc/