[fpc-pascal] order of unit tests

Graeme Geldenhuys graemeg.lists at gmail.com
Mon Dec 8 08:46:29 CET 2008

On Sun, Dec 7, 2008 at 12:10 PM, Marc Santhoff <M.Santhoff at t-online.de> wrote:
> Yes, I agree. But if I do the same reading process in the readers source
> and in the test case I have two spots having the same code. Fixing
> errors or making changes at one place only would be nice.
> How could I solve this problem in a better way?

By using Setup() or TearDown().  You can also use class inheritance.
Create TTestCase descendants implementing your readers source. Then
create your actual test cases, using that new class, instead of
TTestCase directly.

    TMyBaseReaderTestClass   <------ will contain your reader code
    TReaderTestCase           <-- will contain your actual tests


    TReaderTestCase = class(TTestCase)
       procedure Setup;          <--- reader setup code here
       procedure TearDown;
       procedure TestOne;
       procedure TestTwo;

Setup() and TearDown() will be called automatically before and after each test.

  - Graeme -

fpGUI - a cross-platform Free Pascal GUI toolkit

More information about the fpc-pascal mailing list