Testing Qt Applications - Overview

Applies to TestComplete 15.47, last modified on January 20, 2023

This topic provides a brief overview of testing Qt applications with TestComplete.

General Notes on Testing Qt Applications

With TestComplete you can easily test your 32- and 64- bit Qt applications. You can perform any kind of testing – unit, functional, regression and so on. The easiest way to create a test for your application is to record a keyword test or script routine. While playing back a test, TestComplete repeats all the recorded actions you performed over the tested Qt application during recording. If needed, you can also extend the recorded test manually using specific features provided by TestComplete.

TestComplete supports testing Qt applications that are built using a Qt-supported LTS version (5.15 and 6.2), and that were created with a Microsoft® C++ Compiler. You can use the compiler shipped along with Microsoft Visual Studio 2010 and later to compile your applications. Qt library can also be integrated into any other IDE (for example, into Qt Creator).

There are also special TestComplete modules that provide support for earlier Qt versions. These modules cannot be used with the modules that provide support for Qt 5 and 6. They are not included in the TestComplete installation package. You can download them from our web site:

https://support.smartbear.com/downloads/testcomplete/qt-modules/

The package contains detailed information on how to install these modules in TestComplete.

Note: TestComplete does not support applications that use the Qt library compiled for static linkage.

Creating and Recording Tests for Qt Applications

With TestComplete, you can record and play back user actions in Qt 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 Qt 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 opening a combo box drop-down list is represented by the DropDown operation, checking a tool button - by the CheckButton operation, and so on.

A sample keyword test recorded against a Qt application
A sample keyword test recorded against a Qt application

JavaScript, JScript

function Test1()
{
  var textEdit;
  textEdit = Aliases.textedit.TextEdit;
  textEdit.TextEdit.Keys("new text");
  textEdit.ToolBar.ComboBox.DropDown();
  textEdit.ToolBar1.ToolButton1.CheckButton(cbChecked);
}

Python

def Test1():
  textEdit = Aliases.textedit.TextEdit;
  textEdit.TextEdit.Keys("new text");
  textEdit.ToolBar.ComboBox.DropDown();
  textEdit.ToolBar1.ToolButton1.CheckButton(cbChecked);

VBScript

Sub Test1
  Dim textEdit
  Set textEdit = Aliases.textedit.TextEdit
  Call textEdit.TextEdit.Keys("new text")
  textEdit.ToolBar.ComboBox.DropDown
  Call textEdit.ToolBar1.ToolButton1.CheckButton(cbChecked)
End Sub

DelphiScript

procedure Test1;
  var textEdit : OleVariant;
begin
  textEdit := Aliases.textedit.TextEdit;
  textEdit.TextEdit.Keys('new text');
  textEdit.ToolBar.ComboBox.DropDown;
  textEdit.ToolBar1.ToolButton1.CheckButton(cbChecked);
end;

C++Script, C#Script

function Test1()
{
  var textEdit;
  var textEdit2;
  textEdit = Aliases["textedit"]["TextEdit"];
  textEdit["TextEdit"]["Keys"]("new text");
  textEdit["ToolBar"]["ComboBox"]["DropDown"]();
  textEdit["ToolBar1"]["ToolButton1"]["CheckButton"](cbChecked);
}

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 Qt 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 Qt application:

Sample Name Mapping for a Qt application

Here, the ToolButton object is identified only by one property - QtText. This property specifies the object text as it is defined by the application developers in the application’s source code. However, Qt 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 Qt Controls

TestComplete recognizes individual controls of Qt applications and lets you interact with them both at design time and during test recording or playback. In addition, it simplifies testing of the application’s user interface, since it includes special features used to test the most frequently used Qt controls.

For detailed information on support for Qt application controls, see Support for Qt Applications' Controls.

Using Native Qt Methods and Properties in Testing

TestComplete makes visual objects of Qt applications available for testing, that is you can recognize these objects, interact with them and work with native members of internal Qt objects:

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

Viewing Object Properties and Methods

To see what operations (methods) are available for objects in your tested Qt application, as well as the object properties and their values, you can use the Object Browser or Object Spy. The 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 the 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 sample test project that demonstrates how to test Qt applications:

<TestComplete Samples>\Desktop\Orders\Qt

Note: If you do not have the sample, download the TestComplete Samples installation package from the support.smartbear.com/testcomplete/downloads/samples page of our website and run it.

Where to Go Next

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

See Also

Supported Development Tools

Highlight search results