Toad World® Forums

Why isn't my top-level initialization code running for each test case?


#1

I got this question from a user, via Quest Support, today, and thought I would share the answer with you:

The user has some initialization code that he wants to share between a number of test cases. He expected that when they placed this code in the section called “Initialization for all unit tests” (which is reached from the Test Editor -> Properties -> tab Customizations) that this code should have been executed for all test cases. It appears, however, that the code is only executed once.

If, e.g., a DML statement is used, the change is not carried through to the second test case (since a ROLLBACK is performed by Code Tester between each test case).

You can do any DML you like to see the problem, e.g. UPDATE of a table.
You will notice that when the second test case is executed the UPDATE has not been done (the first UPDATE is rolled back after the first test case is executed).


#2

That’s right - initialization code at that level means that it runs once per test (of all units in the specified test definition; for a package, this would mean it runs once before any/all of the unit tests).

Initialization code at the unit test level will run at the start of the test for that unit.

Initialization code at the test case level will run at the start of that test case only.

What the user should do is put that init code in a PROGRAM defined at the top level, and then call that program in the init section of each test case.

We SHOULD make it easier for them to indicate how they want that code to run (and I have added to our ER list), but that’s the way it is right now. I have attached a word doc to show the steps.
Store_and_use_initcode.doc (136 KB)