jeudi 25 juin 2015

How can I return from a calling function to end a test without ending the script?

I am writing automated tests using AutoIt and follow this basic format:

Func MyTest($sInput)
   Local $oTest = NewTest("Test Name")
   $oTest.Setup()
   ;Run steps
   $oTest.Assert($sSomeExpected, $sSomeActual)
   $oTest.Teardown()
EndFunc

Inside the Assert function, I will set the test's result to failed if the assertion fails. What I would like to do is end the test completely, but not end the entire script. That is because my script may look like this:

For $i = 0 To UBound($aInputs) - 1 Step 1
   MyTest($aInputs[$i])
Next

So if the test fails for input 1, I still want to be able to run the test for the other inputs. Ideally, I would like to handle this in Assert:

Func _assert($oSelf, $sExpected, $sActual)
   If Not($sExpected = $sActual) Then
      $oSelf.Result = 0
      ;Return from MyTest function without ending script??
   EndIf
EndFunc

I don't know if it's possible to return from MyTest from inside Assert. I can however exit the script, but as explained I don't want to do that. Even if I went with that approach, this means creating one script for every test which could get bloated extremely quick.

The only workaround I have right now, which is awful, is to return True/False from Assert and check it each time in MyTest:

If Not($oTest.Assert($sSomeExpected, $sSomeActual)) Then Return

But I think that makes my code unreadable and difficult to maintain.

Is there a way to have MyTest return if an Assert fails without handling it each time I call Assert?

Aucun commentaire:

Enregistrer un commentaire