TestComplete Unit Tests - Delphi Applications

Applies to TestComplete 15.64, last modified on June 12, 2024
Information in this topic applies to desktop applications only.

This topic explains how you can create and organize the unit tests of your Delphi applications using TestComplete.

Requirements

  • You must have a license for TestComplete Desktop module.

  • Compile your application as Open with debug information.

  • You must make your test methods as object methods. This corresponds to the unit test structure, in which one testing class tests one or several objects in the application under test. You can create one or more classes that will contain the testing routines.

Note: You cannot create unit tests for MSAA and UIA applications due to their specifics.

Preparing Project for Calling Test Methods via TCUnitTest Project Item

Create testing classes and make them available for TestComplete:

  1. Create testing classes in your application.

    Note that the routines you are going to call from TestComplete must not use parameters. There is no way to supply input values for them.

  2. Use one of the following approaches to make sure Delphi’s smart linker does not exclude your testing routines from the application code:

    • Make your routine published. The linker does not exclude published elements, so they are always present in the application code.

    • Make your routine virtual. The linker does not exclude virtual methods.

    • Call your routine somewhere in your code.

  3. Compile your application with debug information. For detailed instructions on how to do this in various Delphi versions, see the following topics:

    Compiling Delphi XE6, XE7, XE8 and 10 Applications With Debug Information

    Compiling Delphi XE2 – XE5 Applications With Debug Information

    Compiling Delphi XE Applications With Debug Information

    Compiling Delphi 2010 Applications With Debug Information

    Compiling Delphi 2009 Applications With Debug Information

    Compiling Delphi 2007 Applications With Debug Information

    Compiling Delphi 2006 Applications With Debug Information

    Compiling Delphi 7 and 2005 Applications With Debug Information

Calling Test Methods From TestComplete

After you compile your application, you can call test routines from TestComplete:

  1. Launch your Delphi application.

  2. In TestComplete, open your test project and add a TCUnitTest item to the project.

  3. Open the added item in the TCUnitTest editor.

  4. In the Process text box, click the ellipsis button and select the process started by your application in the subsequent dialog.

    Specify the tested project
  5. In the editor, specify the needed tests. To load all tests defined in the application, click Load. To add tests manually, click Add Test and enter the test routine name on the Tests lists. If needed, unite tests into groups.

    TCUnit Test item settings
  6. Choose the test run mode:

    • Automatically load a list of tests and run all tests - Select this option to run all tests defined in the specified application.

    • Run selected tests only - Selecting this option allows you to specify the list of test routines to be run: for this purpose, enable the desired tests and groups and disable those you do not need.

    • Automatically load a list of tests and run without selected tests - Select this option to run all tests defined in the application except for the tests selected on the Tests list.

  7. Once you configure the test, run it.

During the test run, TestComplete considers a test to pass if there are no exceptions during the test routine run. If a tested routine raises an exception, TestComplete will consider the test to fail and will post an error message to the test log.

Note: When TestComplete runs a unit test, it first creates a new instance of the testing class that holds the test routine and then calls the routine. Note that TestComplete does not use existent instances of testing classes. It always creates new instances. That is why a testing class must have a constructor that does not use any parameters.

Alternative to TestComplete Unit Tests

As an alternative, you can create unit tests for your Delphi applications by using the DUnit framework and include them to your test project by using the DUnit items. See –

Running DUnit Tests

Samples

TestComplete includes a sample application that demonstrates unit testing of Delphi applications:

Delphi application:

<TestComplete Samples>\Desktop\Unit Testing\Delphi

TestComplete project:

<TestComplete Samples>\Desktop\Unit Testing\Delphi\TCProject

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.

See Also

Unit Testing
Unit Testing Samples

Highlight search results