delphidelphi-xedunit

DUnit: 'Global' SetUp and TearDown


In DUnit, SetUp and TearDown are called before (and after, respectively) each test method is executed.
In SetUp, I create an object that loads data from a file. This is slow, especially if I have many tests.
Is there any way to call SetUp once, before executing ALL tests (and obviously the same for TearDown)?


Solution

  • From the documentation:

    TTestSetup

    TTestSetup can be used when you wish to set up state exactly once for a test case class (the SetUp and TearDown methods are called once for each test method). For example, if you were writing a suite of tests to exercise some database code, you might subclass TTestSetup and use it to open and close the database before executing the suite.

    An an example how to use TTestSetup