How to access fields of a TTestCase in a TTestSetup class

后端 未结 7 1385
死守一世寂寞
死守一世寂寞 2021-02-07 13:37

I am creating unit tests with DUnit. I have a class that takes quite a long time to initialize.

I derive a class TMyTestSetup from TTestSetup and override its Setup met

7条回答
  •  南旧
    南旧 (楼主)
    2021-02-07 14:27

    You can derive a new Test Suite class from TTestSuite class, and override its SetUp and TearDown methods, then you can add your test cases to this particular test suite, and register the suite.

    This way, Setup and TearDown methods of your test suite class will be called once, and SetUp and TearDown methods of each test case will be called for every test method defined in that test case.

    Execution order will be like this:

    TestSuite.SetUp;
    
    -- TestCase1.Setup;
    ---- TestCase1.Test1;
    -- TestCase1.TearDown;
    -- TestCase1.Setup;
    ---- TestCase1.Test2;
    -- TestCase1.TearDown;
    
    -- TestCase2.Setup;
    ---- TestCase2.Test1;
    -- TestCase2.TearDown;
    -- TestCase2.Setup;
    ---- TestCase2.Test2;
    -- TestCase2.TearDown;
    
    -- TestCaseN.Setup;
    ---- TestCaseN.Test1;
    -- TestCaseN.TearDown;
    -- TestCaseN.Setup;
    ---- TestCaseN.Test2;
    -- TestCaseN.TearDown;
    
    TestSuite.TearDown;
    

提交回复
热议问题