I'm thinking of reworking my TestComplete scripts to follow the format of the various Unit testing frameworks to make it more developer friendly. I was wondering, how to make it easy to have setup() and tearDown() functions called before and after each test. Here's how my proposed test will look like.. (modeled after how most unit testing frameworks are set up) I'm using VBScript
'//These tests, tests the "hello" in "hello world"
Project.Variables.Message = "hello world"
Project.Variables.Message = ""
'tests that "hello" has an "h" in it.
If InStr(Project.Variables.Message, "h") < 1 Then
Log.Error("No 'H' in message.")
'tests that "world" is in the message.
If InStr(Project.Variables.Message, "world" < 1 Then
Log.Error("No 'world" in message.")
So imagine having about 2 dozen of files like this to run. I want to figure out how I can set the "onStopTest" event dynamically so I can switch out the tearDown() function used with each set of tests.
I see what you're getting at. Looks like you have all your steps in modular functions, then composing the test using project items. I guess I can fall back to that if I can't find what I'm looking for.
You can implement event handlers for the OnStartTest and OnStopTest events to make TestComplete call your routine when a test execution is started/stoped. Please see the "Handling Events With TestComplete" help topic for more information. You cannot launch a test item dynamically, however, you can use the Log.AppendFolder method to make TestComplete post messages produced by your event handlers in a separate log folder.
What I want to use it for is to undo whatever potential actions that could have been done with the test. Each test will have a different setup and tearDown (although some tests in the same group will share the same ones.) For example, I have on tests that blocks a port, which I need to make sure gets unblocked before any other tests resumes.
Antoney's suggests worked for me to some degree, but I quickly ran out of name spaces pretty quick as each test item must have a unique name.
Right now I'm falling back on just using excessive exception handling. Making sure anything that can potentially cause a error that can halt the test to be properly encapsulated by exception handling routines.
Ideally, I want to dynamically assign the OnStopTest handler. This way I can switch out the OnStopTest handler for each different test. The closest thing I can think of to that is to set a project variable with a String of code I want to have evaluated, and have a static onStopTest handler call it. That however produced some very difficult code to debug and maintain.
Thanks for your help. I understand some of the issues I'm running into is by the structure of my tests.