snomy Posted November 18, 2007 Share Posted November 18, 2007 Hi 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. Link to comment Share on other sites More sharing options...
Xandl Posted November 18, 2007 Share Posted November 18, 2007 Hello, 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 Else MsgBox(1,$sFunc & " error:",$sErr) Return False EndIf Case Else MsgBox(1,"Function name error:","Not yet implemented: " & $sFunc) EndSwitch EndFunc Func Substract($f1,$f2,$fr) If $f1 - $f2 = $fr Then Return True Return False EndFunc Link to comment Share on other sites More sharing options...
zfisherdrums Posted November 19, 2007 Share Posted November 19, 2007 (edited) 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() StartApp() EndFunc Func TestTearDown() CloseApp() EndFunc Let me know if you need anymore help. Zach... PS: Glad to see another WATIR/N user here. Edited November 19, 2007 by zfisherdrums Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now