Delphi Unit Test Tool Dunit Introduction

Source: Internet
Author: User
Tags class definition

<?xml:namespace prefix = o ns = "Urn:schemas-microsoft-com:office:office"/>

Delphi Unit Test Tool Dunit Introduction

Dunit Basic Introduction

Dunit is a member of the Xunit family and is used for Dephi unit testing. is a tool that extreme programming tests to implement Xtreme testing. Dunit is a free test tool with no code coverage capability.

Dunit's official web Site is https://sourceforge.net/projects/dunit/.

You should first look at the doc/readme.html in the Dunit installation directory using Dunit. This article is also read in the README. Configuring the test environment

The downloaded dunit should be decompressed before using Dunit. The Dunit path is then added to the Library->library path in the menu Tools->environment Options.

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml"/>

Dunit's main document

File

Description

p>

Testframework.pas

The framework itself.

Testextensions.pas

Decorator classes be used to extend test cases.

Guitesting.pas

Classes for testing user Inter Faces (Forms and Dialogs).

Texttestrunner.pas

Routines to Run tests in C Onsole mode.

Guitestrunner.pas

The graphical user Interfac E to the framework:

guitestrunner.dfm

The Guitestrunner Form

p>

Dunit Basic Implementation method (GUI mode)

The basic idea of dunit is to separate the tested Code (unit) from the test Code (unit). Provides a framework and a running interface. All test units should inherit the Ttestcase.

Running the GUI interface

Run TestCase

One thing to note here is that the Setup method and teardown are called when each test method runs, and if you want to run Setup and teardown only once, you should use the Ttestsetup class, which is the Dunit additional features section later. to create a simple example

Create a project that is being tested

Create a project named Betestproject to save the saved Unit1 as a Betestunit.pas file. Rename the TForm1 to Betestform to add a public function betestfunction,betestfunction code as follows:

function Betestform.betestfunction (i,j:integer): integer;

Begin

Result:=i*j;

End

Create a test project

Create a new project

Create another project, named TestProject. If you do not place the same directory with Betestproject, add betestproject to the Library->library path in the menu Tools->environment Options.

Writing TestCase

Delete Unit1 (FORM1), create a unit, note that it is not a form.

Save the created unit as Testunit and add the following code to the interface

Uses

Testframework,betestunit;

Testframework are required for every testcase, and the definitions of the Ttestcase classes to be used later are in Testframework. Betestunit is the unit that will be tested.

To define TestCase, test the class definition code as follows:

Ttestcasefirst = Class (Ttestcase)

Private

Betestform:tbetestform; The class to test

Protected

Procedure SetUp;  Override Initialize class

Procedure TearDown;  Override Clear Data

Published

Procedure Testfirst; The first method of testing

Procedure Testsecond; A second Test method

End

When defining a test method, note that Dunit is looking for and automatically registering for testing by RTTI (RunTime Type information), which is implemented by code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.