Forum Discussion

guillaume's avatar
guillaume
Contributor
14 years ago

How to know if execution is about to finish (Correctly or Exception) ?

Hello.



Let me explain my problem with this small example :


  • I have 3 items in my project

  • I have registered an event listener on the StartTest and the StopTest event.

  • When my 1st test start, I need so set the environment up.

  • When my last test finish, I need to teardown the environment.


Setup environment is very simple : First call of StartTest = SetUp.

TearDown is a bit more complex, we can identify 2 cases :


  1. I know which test is supposed to be executed the last one. Thus, when StopTest test is call for this one, I simply tear down the env.

  2. If this test is never executed (i.e due to previous exception in TestItem2), I won't be to call the clean routine.


I looked into Runner object properties without result. I also looked at others TC Events sources.



Did anyone solve something similar ?



Thank you.



Guillaume.




  • Guillaume,


    You can give the last item some unique name and, within the OnStopTest event handler, check whether the event is triggered for the last item or not. You can use code like this --




    Sub GeneralEvents_OnStopTest(Sender)

      ' Get the current test item

      Set CurrentItem = Project.TestItems.Current


      ' Get the last test item

      IndexOfLastTestItem = Project.TestItems.ItemCount - 1

      Set LastItem = Project.TestItems.TestItem(IndexOfLastTestItem)


      ' Check names

      If CurrentItem.Name = LastItem.Name Then

         ' The test item is the last one

         ' Clean up...

      Else

         ' The test item is not the last one

         ' Don't clean up...

      End If 


    End Sub