<?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
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