![Unit Testing In Delphi With DUnitX Framework | Embarcadero RAD Studio Delphi C++Builder Blogs unit testing in delphi with dunitx framework](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/Unit-Testing-In-Delphi-With-DUnitX-Framework-8809023.png?resize=1140%2C675&ssl=1)
Unit Testing is a type of software testing where specific units or segments of the software are tested. The goal is to validate that each unit of the software code executes as expected. Unit Testing is done during the development of an application by the developers.
DUnitX is an open-source unit test framework based on the NUnit test framework, including some ideas from xUnit as well. The RAD Studio integration of DUnitX framework enables you to develop and execute tests against Win32, Win 64, macOS, and Linux in Delphi applications.
The DUnitX testing framework provides its own set of methods for testing conditions. You can use the provided methods to test a large number of conditions. These methods represent common assertions although you can also create your own custom assertions.
DUnitX is a unit testing framework for Delphi. It makes use of language/RTL features like Generics and Anonymous methods that are not available in older versions of Delphi.
DUnitX Features
- Any class can contain tests
- Attribute-based testing
- An extensive Assert Class
- Setup and TearDown per test method and per test fixture
- API Documented using Xml-Doc
- Console Based Runner
- Wizard for creating new tests
DUnitX is open source and has many hands-on patterns to learn.
Here is some sample source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
unit TestCalcUnit; interface uses DUnitX.TestFramework, CalcUnit; type [TestFixture] TestTCalc = class(TObject) strict private aTCalc: TCalc; public [Setup] procedure Setup; [TearDown] procedure TearDown; // Sample Methods // Test with TestCase Atribute to supply parameters. [TestCase('TestA','8,2,10')] procedure TestAdd(Value1, Value2, _Result: Integer); // Test with TestCase Atribute to supply parameters. [TestCase('TestB','3,4,-1')] procedure TestSub(Value1, Value2, _Result: Integer); end; implementation procedure TestTCalc.Setup; begin aTCalc := TCalc.Create; end; procedure TestTCalc.TearDown; begin aTCalc := nil; end; procedure TestTCalc.TestAdd(Value1, Value2, _Result: Integer); var R: Integer; begin R := aTCalc.Add(Value1, Value2); Assert.AreEqual(R, _Result); // testcode end; procedure TestTCalc.TestSub(Value1, Value2, _Result: Integer); var R: Integer; begin R := aTCalc.Sub(Value1, Value2); Assert.AreEqual(R, _Result); // testcode end; initialization TDUnitX.RegisterTestFixture(TestTCalc); end. |
Head over and check out the DUnitX Unit Testing Framework
Find out more information about DUnitX unit testing in the Embarcadero DocWiki.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition