1 / 11

Programmeerimine Delphi keskkonnas MTAT.03.214

Programmeerimine Delphi keskkonnas MTAT.03.214. Jelena Zaitseva jellen@ut.ee. D U nit - testing framework for Borland Delphi programs http://dunit.sourceforge.net/. Main idea. While developing program code, develop appropriate verification tests at the same time.

Download Presentation

Programmeerimine Delphi keskkonnas MTAT.03.214

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programmeerimine Delphi keskkonnasMTAT.03.214 Jelena Zaitseva jellen@ut.ee

  2. DUnit - testing framework for Borland Delphi programs http://dunit.sourceforge.net/

  3. Main idea • While developing program code, develop appropriate verification tests at the same time. • Keep your tests up-to-date and run them at regular intervals

  4. Main idea • While developing program code, develop appropriate verification tests at the same time. • Keep your tests up-to-date and run them at regular intervals • Benefits: • easiness in producing reliable code • confidence in existing code stability • writing tests also helps you to plan your code structure

  5. Getting started • download DUnit from https://sourceforge.net/projects/dunit/ • in the Delphi IDE set path to DUnit source: Tools  Environment Options  Library

  6. Example: first testing project (1/3) • create a new application • close Unit1.pas (that Delphi automatically generates) without saving it • save new project as FirstTestProject.dpr • create a new unit (FirstTestCase.pas): File  New  Unit. • save it as something like FirstTestCases.pas • declare a class TFirstTestCase derived from TTestCase • implement a single method TestFirst • register the TTestCaseFirst class with the DUnit framework unit FirstTestCase;interfaceusesTestFrameWork;type TFirstTestCase = class(TTestCase)published procedure TestFirst;end;implementationprocedure TFirstTestCase.TestFirst;begin Check(1 + 1 = 2, 'Catastrophic arithmetic failure!');end;initialization TestFramework.RegisterTest(TFirstTestCase.Suite);end.

  7. Example: first testing project (1/3) • create a new application • close Unit1.pas (that Delphi automatically generates) without saving it • save new project as FirstTestProject.dpr • create a new unit (FirstTestCase.pas): File  New  Unit. • save it as something like FirstTestCases.pas • declare a class TFirstTestCase derived from TTestCase • implement a single method TestFirst • register the TTestCaseFirst class with the DUnit framework unit FirstTestCase;interfaceuses TestFrameWork;type TFirstTestCase = class(TTestCase)published procedure TestFirst;end;implementationprocedure TFirstTestCase.TestFirst;beginCheck(1 + 1 = 2, 'Catastrophic arithmetic failure!');end;initialization TestFramework.RegisterTest(TFirstTestCase.Suite);end.

  8. Example: first testing project (2/3) • open the project's source (Project  View Source)and edit it • add TestFrameWork and GUITestRunner to the uses clause • Remove the default Application code, and replace it with the one: program FirstTestProject; uses Forms, TestFrameWork, GUITestRunner, FirstTestCase in 'FirstTestCase.pas'; {$R *.res} begin GUITestRunner.runTest(TestFramework.registeredTests); end.

  9. Example: first testing project (3/3) • run the program no errors occur: error exists:

  10. Test existing projects • create a new application • close Unit1.pas (that Delphi automatically generates) without saving it • save new project as Test<ExistingProject>.dpr(to the same directory where <ExistingProject>.dpr is located) • create new unit(s)for testing. • save it (them)according to testing elements(Test<ClassName>.pas) • declare a class TTest<ClassName> derived from TTestCase • add units (of <ExistingProject>.dpr) to be tested to the project Test<ExistingProject>.dpr: Project Add to Project... • implement test-methods • register the TTest<ClassName> with the DUnit framework • open the project's source (Project  View Source)and edit it • add TestFrameWork and GUITestRunner to the uses clause • Remove the default Application code, and replace it with the GUITestRunner.runTest(TestFramework.registeredTests); • run the program (i.e. tests)

  11. Test suites • Test suites– tests that can contain other tests (including other test suites) RegisterTest('Simple suite', TTestTrivial1.Suite);RegisterTest('Simple suite', TTestTrivial2.Suite); function SomeTrivialTests: ITestSuite;begin Result := TTestSuite.Create('Some trivial tests', [ TTestTrivial1.Suite, TTestTrivial2.Suite ]);end; initialization RegisterTest('Simple Trivial Test', SomeTrivialTests);end.

More Related