Friday, April 30, 2010

Unit tests data setup and tear down

There are methods in AX to setup data before test execution and tear it down afterwards - SysTestCase.setup() and SysTestCase.tearDown(). Those methods will be executed before and after each test method in a unit test class.
In AX 2009 two new methods were added - setupTestCase() and tearDownTestCase() which are executed only once per unit test class execution - before first test method and after last test method. But there is a problem with using them - by default each unit test method runs in a separate instance of the unit test class, so if you are setting up some data in the setupTestCase() method there will be no possibility to store a reference to it in the instance variable.
To change this behavior useSingleInstance() method can be overridden to return true. In this case all test method as well as setupTestCase() and tearDownTestCase() method will be execute in one instance of the unit test class.

16 comments:

  1. Hello! Thank you! I am interesting Microsoft since I was a kid and this information was good and interesting for me. It is really very useful information. Thank you that you leave links to download and upgrade versions:)))))))

    ReplyDelete

  2. بسم الله الرحمن الرحيم نحن فى شركة الكمال نقوم بكشف التسربات من خلال امببة هواء مزواده بالعداد هواء كما يوجد لدينا جهاز الكترنى يكشف عن طريق التزبزبات
    شركة كشف تسربات المياه بالطائف
    شركة كشف تسربات المياه بجازان
    شركة كشف تسربات المياه بحائل
    والسلامة عليكم ورحمة الله وبركاته

    ReplyDelete