Jump to content
Sign in to follow this  

Assertions in AutoIt

Recommended Posts



I am a complete newbie to AutoIt and its VB style syntax, I have mostly been using WATIR on web apps over the last 6 months, but my current plan is to automate a window app, and AutoIt seems the best tool for doing so.

However, are Assertions supported? In Watir they are provided as part of the API, but I cant see any information on them in the AutoIt help files etc.

Does this mean they have to be self written, or is there a plug in required to access these functions?

I traced a piece of code in an AutoIt forum which appears to show that Assertions are supported, see below...

Test( "Subtract" )

AssertEqual( Subtract( 2.5, 3.6 ), -1.1, "This calculator cannot subtract" )

However when I use this code in testing my calculator, the script states its an unknowin function?

Please give me some help on assertions and how to use them if they are applicable.

Thanks in advance.

Share this post

Link to post
Share on other sites


assertions are not provided directly, I think. But you can implement that like this:

AssertEqual('Substract',2.5,3.6,-1.1,'This calculator cannot substract')
AssertEqual('Substract',2.5,3.6,-1.11,'This calculator cannot substract')

Func AssertEqual($sFunc,$v1,$v2,$r1,$sErr)
    Switch $sFunc
        Case 'Substract'
            If Substract($v1,$v2,$r1) Then
                Return True
                MsgBox(1,$sFunc & " error:",$sErr)
                Return False
        Case Else
            MsgBox(1,"Function name error:","Not yet implemented: " & $sFunc)

Func Substract($f1,$f2,$fr)
    If $f1 - $f2 = $fr Then Return True
    Return False

Share this post

Link to post
Share on other sites

Hello snomy,

First, welcome to the forums!

Second, looks like you were looking at my implementation of unit testing for AutoIt. To utilize it, you'll need to save the "Testing.au3" file to your include files ( usually "c:\program files\AutoIt3\include" ). That file is available via the link in my signature.

Also, one shouldn't put the function call inside the AssertX functions; that breaks what little "encapsulation" we have approximated.

Finally, because my version makes a call to TestSetup and Teardown functions, they should be defined in the script (see comment from "ActionLibTests.au3" )

; Function with the name "TestSetup" and "TestTearDown" are executed
; before and after every test. Test scripts should include these
; functions to prevent non-fatal AU3check errors.
Func TestSetup()

Func TestTearDown()

Let me know if you need anymore help.


PS: Glad to see another WATIR/N user here.

Edited by zfisherdrums

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.