Turn your manual testers into automation experts Request a DemoStart testRigor Free

ASP.Net Testing

ASP.Net Testing

ASP.NET is part of Microsoft’s .NET ecosystem that offers a host of capabilities for building applications and services. ASP stands for ‘active server page’, which deals with the backend scripting of web pages. ASP.NET is an open-source framework that is widely used to build web applications. It offers frameworks such as Web Forms, ASP.NET MVC, and ASP.NET Web Pages for developing web pages. Depending on your use case, you can use three of these frameworks in combination. Although ASP.NET was intended for server-side scripting for Windows-based applications, Microsoft has extended this to other platforms with their ASP.NET Core framework. You can read more about the differences between these frameworks here.

When it comes to testing ASP.NET framework-based applications, these are the primary testing types:

Unit Testing

Unit testing forms the basis of the testing activities where you validate if every unit of code is functioning as expected. These tests are usually faster and less expensive in comparison to integration and end-to-end testing methods. The ASP.NET framework offers support to the following tools to perform unit testing.

With the .NET CLI or other IDEs, you can easily execute your unit tests. Additionally, Visual Studio, which is another product by Microsoft, is a great IDE to write test cases in as it seamlessly supports .NET-related tools and frameworks.

For writing your test cases, you can keep in mind the arrange, act, and assert flows. With this approach, you first need to arrange your dependencies for the test, act on them by writing the test, and assert the outcome. In the .NET Core framework, irrespective of whether the pages are designed using the Razor pages framework or MVC, unit tests should be written.

Below is a sample of a unit test:
[Fact]
public async Task Post_DeleteAllMessagesHandler_ReturnsRedirectToRoot()
{
  // Arrange
  var defaultPage = await _client.GetAsync("/");
  var content = await HtmlHelpers.GetDocumentAsync(defaultPage);

  //Act
  var response = await _client.SendAsync(
      (IHtmlFormElement)content.QuerySelector("form[id='messages']"),
      (IHtmlButtonElement)content.QuerySelector("button[id='deleteAllBtn']"));

  // Assert
  Assert.Equal(HttpStatusCode.OK, defaultPage.StatusCode);
  Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
  Assert.Equal("/", response.Headers.Location.OriginalString);
}

Integration Testing

Integration tests are meant to verify if two or more components are working together properly. This is generally a wide term, covering different layers of testing activities. Quite often, the test cases target those scenarios where integrations with databases, file systems, network infrastructure, or other components are expected. Unlike unit tests, where you fake or mock input parameters, integration tests utilize real data.

Some ways of writing integration tests are:
  • Checking crucial read-write operations into databases.
  • Services can be tested by mocking HTTP calls.
  • Validating GET and POST routes, controllers, and pipelines.

You can utilize the TestServer class available, which helps mimic HTTP calls for facilitating integration tests. It makes the execution of your tests faster.

The example below is of an integration test case to check if the correct players are being displayed.
public class PlayersControllerIntegrationTests : IClassFixture>
{
  private readonly HttpClient _client;
  
  public PlayersControllerIntegrationTests(CustomWebApplicationFactory factory)
  {
    _client = factory.CreateClient();
  }
  
  [Fact]
  public async Task CanGetPlayers()
  {
    // The endpoint or route of the controller action.
    var httpResponse = await _client.GetAsync("/api/players");
  
    // Must be successful.
    httpResponse.EnsureSuccessStatusCode();
  
    // Deserialize and examine results.
    var stringResponse = await httpResponse.Content.ReadAsStringAsync();
    var players = JsonConvert.DeserializeObject>(stringResponse);
    Assert.Contains(players, p => p.FirstName=="Jake");
    Assert.Contains(players, p => p.FirstName == "Erica");
  }
}
Another example that validates whether response headers are appropriate after sending a URL request:
public class BasicTests 
    : IClassFixture<WebApplicationFactory<RazorPagesProject.Startup>>
{
  private readonly WebApplicationFactory<RazorPagesProject.Startup> _factory;

  public BasicTests(WebApplicationFactory<RazorPagesProject.Startup> factory)
  {
      _factory = factory;
  }

  [Theory]
  [InlineData("/")]
  [InlineData("/Index")]
  [InlineData("/About")]
  [InlineData("/Privacy")]
  [InlineData("/Contact")]
  public async Task Get_EndpointsReturnSuccessAndCorrectContentType(string url)
  {
      // Arrange
      var client = _factory.CreateClient();

      // Act
      var response = await client.GetAsync(url);

      // Assert
      response.EnsureSuccessStatusCode(); // Status Code 200-299
      Assert.Equal("text/html; charset=utf-8", 
          response.Content.Headers.ContentType.ToString());
  }
}

End-to-End Testing

End-to-end testing involves verifying a complete workflow. The goal of such tests is to emulate entire user flows, making sure that all components behave well together. End-to-end tests are performed on the UI layer – and the closer your test can resemble real user behavior, the better. End-to-end tests are typically the slowest among the three types of testing discussed in this article; however, they are also the most accurate. While developers typically write unit tests, end-to-end tests are commonly written by the QA team.

You can build these types of tests with the following tools:
  • Selenium-based tools
  • testRigor

Selenium-based tools for end-to-end testing

Selenium is synonymous with testing and is widely used. There are many tools available that simplify adopting Selenium for testing. However, each of these tools does inherit some of the drawbacks that Selenium has, though they try to overcome most of them. There are hundreds of articles that you can easily find on this topic, so we won’t cover it here in greater detail.

testRigor for end-to-end testing

testRigor is a powerful, no-code automation solution that allows you and your team to express commands in plain English, thus making it very easy to create automated test cases.

  1. Its AI-powered engine can interpret the relative position of the element from the mentioned command. Thus any changes in the locator value of the element do not break the test. It also provides the capability to test by comparing images to find the element.
  2. testRigor supports cross-platform and cross-browser testing without major configuration steps.
  3. Provides support for typing and copy-pasting use cases.
  4. Has provision to support 2FA testing support for Gmail, text messages, and Google authenticator.
  5. Easy integration with most CI/CD tools.
  6. Facilitates easy mocking of API calls and accessing databases if needed.

The tool provides good reporting capabilities, which can help you review and understand issues in your test cases, if any.

Here’s a test example:
hover over "Account & Lists"
click "Sign in"
Check that the page contains "Sign in"
Enter stored value "mobilePhone" in "Email and mobile phone number"
Enter stored value "password" in "Password"
Click on "Sign in"
Select "office products" from "category"
Enter "table organizer" in "Search"
Click on "search" to the left of "EN"
Select "HermanMiller" from "Brands"
Click on 1st "HermanMiller Office Chair"
Click on "Add gift options"
Click on "Add to cart"

How to do End-to-end Testing with testRigor

Let us take the example of an e-commerce website that sells plants and other gardening needs. We will create end-to-end test cases in testRigor using plain English test steps.

Step 1: Log in to your testRigor app with your credentials.

Step 2: Set up the test suite for the website testing by providing the information below:

  • Test Suite Name: Provide a relevant and self-explanatory name.
  • Type of testing: Select from the following options: Desktop Web Testing, Mobile Web Testing, Native and Hybrid Mobile, based on your test requirements.
  • URL to run test on: Provide the application URL that you want to test.
  • Testing credentials for your web/mobile app to test functionality which requires user to login: You can provide the app’s user login credentials here and need not write them separately in the test steps then. The login functionality will be taken care of automatically using the keyword login.
  • OS and Browser: Choose the OS Browser combination on which you want to run the test cases.
  • Number of test cases to generate using AI: If you wish, you can choose to generate test cases based on the App Description text, which works on generative AI.

Step 3: Click Create Test Suite.

On the next screen, you can let AI generate the test case based on the App Description you provided during the Test Suite creation. However, for now, select do not generate any test, since we will write the test steps ourselves.

Step 4: To create a new custom test case yourself, click Add Custom Test Case.

Step 5: Provide the test case Description and start adding the test steps.

For the application under test, i.e., e-commerce website, we will perform below test steps:

  • Search for a product
  • Add it to the cart
  • Verify that the product is present in the cart

Test Case: Search and Add to Cart

Step 1: We will add test steps on the test case editor screen one by one.

testRigor automatically navigates to the website URL you provided during the Test Suite creation. There is no need to use any separate function for it. Here is the website homepage, which we intend to test.

First, we want to search for a product in the search box. Unlike traditional testing tools, you can identify the UI element using the text you see on the screen. You need not use any CSS/XPath identifiers.

For this search box, we see the text “What are you looking for?” So, to activate the search box, we will use the exact text in the first test step using plain English:
click "What are you looking for?"

Step 2: Once the cursor is in the search box, we will type the product name (lily), and press enter to start the search.

type "lily"
enter enter

Search lists all products with the “lily” keyword on the webpage.

Step 3: The lily plant we are searching for needs the screen to be scrolled; for that testRigor provides a command. Scroll down until the product is present on the screen:

scroll down until page contains "Zephyranthes Lily, Rain Lily (Red)"

When the product is found on the screen, testRigor stops scrolling.

Step 4: Click on the product name to view the details:

click "Zephyranthes Lily, Rain Lily (Red)"

After the click, the product details are displayed on the screen as below, with the default Quantity as 1.

Step 5: Lets say, we want to change the Quantity to 3, so here we use the testRigor command to select from a list.

select "3" from "Quantity"
After choosing the correct Quantity, add the product to the cart.
click "Add to cart"

The product is successfully added to the cart, and the “Added to your cart:” message is displayed on webpage.

Step 6: To assert that the message is successfully displayed, use a simple assertion command as below:

check that page contains "Added to your cart:"

Step 7: After this check, we will view the contents of the cart by clicking View cart as below:

click "View cart"

Step 8: Now we will again check that the product is present in the cart, under heading “Your cart” using the below assertion. With testRigor, it is really easy to specify the location of an element on the screen.

check that page contains "Zephyranthes Lily, Rain Lily (Red)" under "Your cart"

Complete Test Case

Here is how the complete test case will look in the testRigor app. The test steps are simple in plain English, enabling everyone in your team to write and execute them.

Click Add and Run.

Execution Results

Once the test is executed, you can view the execution details, such as execution status, time spent in execution, screenshots, error messages, logs, video recordings of the test execution, etc. In case of any failure, there are logs and error text that are available easily in a few clicks.

You can also download the complete execution with steps and screenshots in PDF or Word format through the View Execution option.

testRigor’s Capabilities

Apart from the simplistic test case design and execution, there are some advanced features that help you test your application using simple English commands.

  • Reusable Rules (Subroutines): You can easily create functions for the test steps that you use repeatedly. You can use the Reusable Rules to create such functions and call them in test cases by simply writing their names. See the example of Reusable Rules.
  • Global Variables and Data Sets: You can import data from external files or create your own global variables and data sets in testRigor to use them in data-driven testing.
  • 2FA, QR Code, and Captcha Resolution: testRigor easily manages the 2FA, QR Code, and Captcha resolution through its simple English commands.
  • Email, Phone Call, and SMS Testing: Use simple English commands to test the email, phone calls, and SMS. These commands are useful for validating 2FA scenarios, with OTPs and authentication codes being sent to email, phone calls, or via phone text.
  • File Upload/ Download Testing: Execute the test steps involving file download or file upload without the requirement of any third-party software. You can also validate the contents of the files using testRigor’s simple English commands.
  • Database Testing: Execute database queries and validate the results fetched.

testRigor enables you to test web, mobile (hybrid, native), API, and desktop apps with minimum effort and maintenance.

Additional Resources

Conclusion

The .NET ecosystem comprises multiple frameworks, such as ASP.NET and ASP.NET Core. All these frameworks can be tested at various stages using strategies and tools described above based on your needs. We recommend having tests on each layer, which will lead to an optimal and robust testing strategy.

You're 15 Minutes Away From Automated Test Maintenance and Fewer Bugs in Production
Simply fill out your information and create your first test suite in seconds, with AI to help you do it easily and quickly.
Achieve More Than 90% Test Automation
Step by Step Walkthroughs and Help
14 Day Free Trial, Cancel Anytime
“We spent so much time on maintenance when using Selenium, and we spend nearly zero time with maintenance using testRigor.”
Keith Powe VP Of Engineering - IDT