About Testing .NET Applications

Applies to TestComplete 15.31, last modified on March 17, 2022

TestComplete allows you to create and run automated tests for .NET applications. This topic explains basic concepts of .NET application testing.

Overview of Supported .NET Technologies

With TestComplete, you can create and run automated tests for .NET applications. You can test:

  • 32-bit as well as 64-bit .NET applications.

  • .NET applications running under the same or different user account.

  • .NET applications installed on the local computer, running from network shares as well as via no-touch deployment.

  • .NET applications created with .NET 2.0 - 4.8 (both 32-bit and 64-bit).

  • .NET Core applications created with .NET Core 3.0 - 3.1 and .NET 5.0 - 6.0 (both 32-bit and 64-bit).

For more information, see Supported .NET Technologies.

Creating and Recording Tests for .NET Applications

With TestComplete, you can record and play back user actions in .NET applications, or you can create tests manually from scratch. Usually, it is easier to record the test first and then modify and enhance the recorded test.

When you record a test, you interact with the tested .NET application as an end-user would: navigate through the application’s screens, fill out forms and so on. TestComplete captures all actions you perform in the application and adds them to the test.

A test consists of a sequence of operations that define various interactions with objects in the tested application. For example, in the sample test below you can see that item selection from a combo box is represented by the ClickItem operation, text input into text boxes - by the SetText operation, and so on.

A sample keyword test recorded against a .NET application
A sample keyword test recorded against a .NET application

JavaScript, JScript

function Test()
{
  var orderForm;
  var groupBox;
  var textBox;
  orderForm = Aliases.Orders.OrderForm;
  groupBox = orderForm.Group;
  textBox = groupBox.Customer;
  textBox.Click(73, 13);
  textBox.SetText("John Smith");
  groupBox.ProductNames.ClickItem("FamilyAlbum");
  orderForm.ButtonOK.ClickButton();
}

Python

def Test():
  orderForm = Aliases.Orders.OrderForm;
  groupBox = orderForm.Group;
  textBox = groupBox.Customer;
  textBox.Click(73, 13);
  textBox.SetText("John Smith");
  groupBox.ProductNames.ClickItem("FamilyAlbum");
  orderForm.ButtonOK.ClickButton();

VBScript

Sub Test1
  Dim orderForm
  Dim groupBox
  Dim textBox
  Set orderForm = Aliases.Orders.OrderForm
  Set groupBox = orderForm.Group
  Set textBox = groupBox.Customer
  Call textBox.Click(73, 13)
  Call textBox.SetText("John Smith")
  Call groupBox.ProductNames.ClickItem("FamilyAlbum")
  orderForm.ButtonOK.ClickButton
End Sub

DelphiScript

procedure Test;
  var orderForm : OleVariant;
  var groupBox : OleVariant;
  var textBox : OleVariant;
begin
  orderForm := Aliases.Orders.OrderForm;
  groupBox := orderForm.Group;
  textBox := groupBox.Customer;
  textBox.Click(73, 13);
  textBox.SetText('John Smith');
  groupBox.ProductNames.ClickItem('FamilyAlbum');
  orderForm.ButtonOK.ClickButton;
end;

C++Script, C#Script

function Test()
{
  var orderForm;
  var groupBox;
  var textBox;
  orderForm = Aliases["Orders"]["OrderForm"];
  groupBox = orderForm["Group"];
  textBox = groupBox["Customer"];
  textBox["Click"](73, 13);
  textBox["SetText"]("John Smith");
  groupBox["ProductNames"]["ClickItem"]("FamilyAlbum");
  orderForm["ButtonOK"]["ClickButton"]();
}

The recorded tests can be modified and enhanced in a number of ways to create more flexible and efficient tests. For example, you can:

  • Add new operations, reorder operations and modify their parameters.

  • Delete or disable unneeded operations (for example, superfluous recorded operations).

  • Insert checkpoints for verifying objects and values in the tested application.

  • Create data-driven tests that run multiple test iterations using different sets of data.

Refer to the following topics to learn more about creating and enhancing tests:

Task See topic…
Creating tests using recording Recording Tests
Creating tests manually Keyword Testing and Scripting
Simulating user actions Working With Application Objects and Controls
Running tests Running Tests
Launching applications automatically at the beginning of the test run Adding Tested Applications and
Running Tested Applications
Creating checkpoints for verifying application behavior and state Checkpoints
Running multiple test iterations using data from an external file Data-Driven Testing

About Test Types

There are two major test formats in TestComplete:

  • Keyword tests - visually configured tests with grid-based editing interface. Best suited for novice users and those without programming knowledge.

  • Scripts - code written in one of the supported scripting languages. May be better suited for advanced users.

You select the test type when creating a test and cannot change it later. However, you can mix keyword tests and scripts within the same test project and call them from each other.

TestComplete also includes additional test types, such as low-level procedures, unit tests, and so on. You can use them to address specific testing needs. However, most automation is typically done using keyword tests and scripts.

About .NET Object Identification and Name Mapping

Each object in an application has a number of properties, such as its location, text, type and so on. Some object properties are persistent and unchanging, and therefore can be used to locate objects in applications and differentiate among various objects.

When you record a test, TestComplete captures all windows and controls that you interacted with during the recording session and adds them to the Name Mapping project item (also known as the object repository or GUI map). For each captured object, TestComplete does the following:

  • Selects a set of properties and values that uniquely identify the object in the application and saves them to Name Mapping as the object identification criteria. These properties will be used for locating the object during subsequent test recording, editing and run sessions.

  • Generates an alias (name) that will be used to reference this object in tests. By default, TestComplete generates aliases based on object names defined in the application by developers.

  • Automatically captures and adds images of the mapped objects to the Name Mapping repository. This helps you understand which window or control one or another mapped object matches.

The following image shows sample Name Mapping for a .NET application:

Sample Name Mapping for a .NET application

Here, the Customer object is identified only by one property - WinFormsControlName. This property specifies the object name as it is defined by the application developers in the application’s source code. However, .NET application objects can also be located by other properties, such as their class name, text and so on -- whatever best identifies a specific object.

If needed, you can modify the default Name Mapping generated by TestComplete. For example, you can:

For more information, see Name Mapping.

Keep in mind that the object hierarchy in Name Mapping mirrors the object hierarchy in the tested application. When locating an object, TestComplete takes into account its entire parent hierarchy. If any object in the parent hierarchy cannot be found using the specified property values, the target object cannot be located as well. That is why it is important to select unique and unchanging properties for object identification.

About Support for .NET Controls

TestComplete supports many standard and third-party .NET controls. It provides many built-in operations for automating various user interactions with these controls: item selection, grid cell clicks, tree node expanding, data retrieval and so on. When you record a test, TestComplete records the performed GUI actions using these special operations.

To learn which operations are available for a specific object, you can examine this object in the Object Browser or Object Spy.

For more information, see Support for .NET Applications' Controls.

Using Native .NET Methods and Properties in Testing

For most flexible and powerful automation possible, TestComplete not only provides built-in test objects, methods and properties, but also exposes all native properties and methods of objects in .NET applications. These are the same properties and methods that are available in the application’s source code and used by the application developers. You can use these native properties and methods to automate custom operations that are not available out of the box.

Note: Note that, some native properties and methods of .NET objects are unavailable to TestComplete. For more information, see Object Properties, Fields and Methods That Are Unavailable to TestComplete.

For detailed information on how to address exposed properties and methods from your tests, see Accessing Native Properties and Methods of .NET Objects and Addressing Objects in .NET Applications.

Viewing Object Properties and Methods

To see what operations (methods) are available for objects in your tested application, as well as the object properties and their values, use the Object Browser or Object Spy. Available properties and methods include those provided by TestComplete, as well as native object properties and methods defined by the developers in the application’s source code.

You can view object properties and methods both at design time and at run time when the test is paused.

For more information on using the Object Browser, see Object Browser and Exploring Applications.

Samples

TestComplete includes a number of sample .NET applications and test projects for them. You can examine these samples to better understand how to implement some common automated testing scenarios.

Sample Location Description
<TestComplete Samples>\Desktop\Orders\C# A general purpose testing sample for the sample Orders application created with C#.
<TestComplete Samples>\Desktop\Checkpoints\ Examples of using database, table and XML checkpoints for verifying .NET applications.
<TestComplete Samples>\Common\Data-Driven Testing\ Example of data-driven testing of the Orders application using data from an Excel file.

For information about sample applications and test projects included in TestComplete, see Getting Started With TestComplete.

Where to Go Next

For further information about automating tests with TestComplete, refer to the following sections:

See Also

Testing .NET Applications
Requirements for Testing .NET Applications
Addressing Objects in .NET Applications
Support for .NET Applications' Controls

Highlight search results