Forum Discussion

DanielM75's avatar
DanielM75
Occasional Contributor
6 years ago

Deciding if a test passes or fails

Hello

So I am new to Test Complete.

I have written some tests, recorded some scripts etc and it is going well.

However, I am unclear on how I can tell my test when I want it to pass or fail.

 

e.g. suppose I have a desktop application

I have a customers current $ balance

I simulate them depositing $100 into their account

I then want to check that their balance is $100 more than at the start of my test

 

All of this I can do.

But how do I tell TestComplete that the test passes if the balance is $100 more than at the start, but fails if it is not.

Currently TestComplete passes the test if it gets to the end without errors.  If it gets to the end but the balance didn't go up by $100 is still passes the test as it is finished.

  • Wamboo's avatar
    Wamboo
    Community Hero

    YO!

     

    In script mode You can use these solutions:

     

    1) https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqobject/checkproperty.html

     

    2) Create condition and use within a:

      - Log.Checkpoint()

      - Log.Error() -> this one set test item to status "fail"

      - Log.Warning()

     

    3) You can also use the Runner class
    https://support.smartbear.com/testcomplete/docs/reference/project-objects/items/script/runner/index.htm

     

     

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Wamboo 's suggestions are right on point. 

         

        Basically, if you think about how you do test manually, you go through checks.  

         

        For the example you gave, as a manual tester, you first make a note of the current balance.  You then perform the action.  Then you make a note of the ending balance.  Then you subtract one from another.  Then you check to see if that result = 100.

         

        Translate that into an automated test.

         

        1) Make note of the current balance -> Create a variable in your test and store the contents of the property of the on-screen component that contains the balance into that variable.  

        e.g. 

        var startingBalance;
        
        startingBalance = Aliases.myApp.myForm.customerBalance.wText

        2) Run the test

        3) Record the ending balance after the test

         

        e.g.

        var endingBalance
        
        endingBalance = Aliases.myApp.myForm.customerBalance.wText

        4) Subtract the values and store the difference -> You'll need to convert the string on screen to an integer and subtract.  Of course, if there are special symbols like $ or something for currency, you may need to peel those out.  But, generically.

         

        var balanceDifference
        
        startingBalance = aqConvert.VarToInt(startingBalance)
        endingBalance = aqConvert.VarToInt(endingBalance)
        
        balanceDifference = endingBalance - startingBalance

        5) Now, check that difference for the desired amount.

         

        if (balanceDifference = 100) then Log.Message("The test passed")
        else Log.Error("The test failed")

        Your job, as an automated tester, is to translate what you do in manual tests into code.  What I've described above probably has some fine tuning that you could do to it, you could use property checkpoints in some way as well, but effectively, that's how you write an automated test.