AutoHotkey Community

It is currently May 26th, 2012, 9:55 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [module] UTest v0.3
PostPosted: September 25th, 2009, 4:51 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade

_________________
Image


Last edited by majkinetor on September 21st, 2010, 3:24 pm, edited 5 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2009, 11:08 am 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
I ever wanted to learn how to make unit tests.

Can you give me a short Exampletest (with a function to test)?

Thanks a lot!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2009, 12:04 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Check out the Parse function. Tests helped me a lot to track regression bugs.

Since AHK is automation language, UTest is very simple. Well known frameworks like Ranorex, NUnit etc... all have parts of the framework to enable more difficult tests (web, gui, mocks etc..) however, AHK has most of that available already.

In agile development u typically have hundreeds of tests so, being able to automate them is essential.

One ability I would like to have, but I don't know if its possible, is to find out the line of Assert function calls inside Test functions, to find out which Assert failed if you have more then 1 in test. It would also be cool in order to jump to failed assertion (something unit frameworks usualy have). However, I didn't find out is that possible to do using LowLevel.ahk.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2009, 3:27 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
Thanks again,
Utest will be very useful (.. as much as all your other work)!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 1st, 2009, 3:22 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
*** version 0.2 ***
+ Added names and params.
+ Invalid tests are selected
+ Editor is open on double click
+ Docs improvements.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 1st, 2010, 2:29 am 
majkinetor wrote:
Since AHK is automation language, UTest is very simple. Well known frameworks like Ranorex, NUnit etc... all have parts of the framework to enable more difficult tests (web, gui, mocks etc..) however, AHK has most of that available already.


can you elaborate?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 1st, 2010, 9:59 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Clicking buttons, getting informed about control status and content etc is native in AHK. Other languages usually have this implemented as a GUI testing feature. There are also some other functions that could be used for testing like PixelSearch or URLDownload and also some user created libraries like Accessibility COM interface.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 1st, 2010, 3:29 pm 
i guess i'm just looking for more examples of how to use this. my script has lots of guis and set timers and hotkeys and i'm finding it difficult figuring out how to write tests for my code. seems like this is easiest used with functions

nitpick request:
i think 'OK' should be displayed green in contrast to red for 'FAIL'


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2010, 12:46 am 
guest3456 wrote:

nitpick request:
i think 'OK' should be displayed green in contrast to red for 'FAIL'


ok, i implemented this, but not sure if its the best way to do it. i didnt see any other way of changing the font color from another function, other than using the build in ahk gui variables. DllCall("CreateFont") and then SendMessage, WM_SETFONT wouldnt work, since CreateFont didnt have a color parameter

relevant code:

Code:
UTest_start( bNoGui = false) {
   if !bNoGui
      hGui := UTest_CreateGui()
   s := UTest_RunTests()
   
   if (hGui){
      ;Result := UTest("TestsFail") ? "FAIL" : "OK"
      ;ControlSetText,Static1, %Result%, ahk_id %hGui%
      if UTest("TestsFail") {
         Result := "FAIL"
         Gui, %hGui%: Font, cRed
      } else {
         Result := "OK"
         Gui, %hGui%: Font, cGreen
      }
      GuiControl, %hGui%: Font, ResultText
      GuiControl,, ResultText, %Result%

   }
   return s
}

UTest_createGui() {
   global ResultText
   w := 500, h := 400
   n := UTest_getFreeGuiNum()

   Gui, %n%: +LastFound +LabelUTest_
   hGui := WinExist()
   Gui, %n%: Add, ListView, w%w% h%h% gUTest_OnList, Result|Test|Line|Name|Param
   Gui, %n%: Font, s20 bold cRED, Courier New
   Gui, %n%: Add, Text, w%w% h40 vResultText
   Gui, %n%: Show,autosize, UTest - %A_ScriptName%
   UTest("GUINO", n)

   Hotkey, ifWinActive, ahk_id %hGui%
   Hotkey, ESC, UTest_Close
   Hotkey, ifWinActive
   ;return hGui
   return n


 UTest_Close:
    ExitApp
 return
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2010, 2:00 am 
is it possible to add 'expected' and 'actual' columns to the listbox?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2010, 6:03 am 
guest3456 wrote:
guest3456 wrote:

nitpick request:
i think 'OK' should be displayed green in contrast to red for 'FAIL'


ok, i implemented this, but not sure if its the best way to do it. i didnt see any other way of changing the font color from another function, other than using the build in ahk gui variables. DllCall("CreateFont") and then SendMessage, WM_SETFONT wouldnt work, since CreateFont didnt have a color parameter


some more work to try to avoid using the built in gui global..

SetTextColor directly didn't work either:

Code:
;// does not work

UTest_start( bNoGui = false) {
   if !bNoGui
      hGui := UTest_CreateGui()
   s := UTest_RunTests()
   
   if (hGui){
      ;Result := UTest("TestsFail") ? "FAIL" : "OK"

      ControlGet, texthwnd, hwnd,, Static1, ahk_id %hGui%
      hDC := DllCall("user32.dll\GetDC", "UInt", texthwnd)

      if UTest("TestsFail") {
         Result := "FAIL"
         oldcolor := DllCall("gdi32.dll\SetTextColor", "UInt", hDC, "UInt", 0x000000FF)         
      } else {
         Result := "OK"
         oldcolor := DllCall("gdi32.dll\SetTextColor", "UInt", hDC, "UInt", 0x0000FF00)         
      }

      DllCall("gdi32.dll\ReleaseDC", "UInt", hGui, "UInt", hDC)


      ControlSetText,Static1, %Result%, ahk_id %hGui%
   }
   return s
}


but this does work:
requires:
CColor from Forms Framework
(http://www.autohotkey.com/forum/topic53317.html)

GetSysColor
(http://www.autohotkey.com/forum/topic60215.html)

Code:
#include CColor.ahk

UTest_start( bNoGui = false) {
   if !bNoGui
      hGui := UTest_CreateGui()
   s := UTest_RunTests()
   
   if (hGui){
      ;Result := UTest("TestsFail") ? "FAIL" : "OK"

      ControlGet, texthwnd, hwnd,, Static1, ahk_id %hGui%

      bgcolor := GetSysColor(15)  ; Window Background color for the current desktop theme

      if UTest("TestsFail") {
         Result := "FAIL"
         CColor(texthwnd, bgcolor, "red")
      } else {
         Result := "OK"
         CColor(texthwnd, bgcolor, "green")
      }
     

      ControlSetText,Static1, %Result%, ahk_id %hGui%

   }
   return s
}

;// http://www.autohotkey.com/forum/topic60215.html
GetSysColor( DisplayElement=1 ) {
 VarSetCapacity( HexClr,7,0 ), SClr := DllCall( "GetSysColor", UInt,DisplayElement )
 RGB := ( ( ( SClr & 0xFF) << 16 ) | ( SClr & 0xFF00 ) | ( ( SClr & 0xFF0000 ) >> 16 ) )
 DllCall( "msvcrt\sprintf", Str,HexClr, Str,"%06X", UInt,RGB )
Return HexClr
}



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2010, 9:01 am 
Offline

Joined: August 25th, 2010, 2:32 pm
Posts: 36
Hi majkinetor,

I'm getting a blank window when I tried using this. No results for the tests I made, nor for the included _Test.ahk example, nor the test included in your Parse.ahk library. Blank meaning no test results, even though the form headers are shown. Shouldn't I get either an OK or a Fail?

Using _L59 version.

Here's my test of your UTest

Code:
; mylib.ahk
MyName()
{
    Return "justjim"
}


Code:
; mylib_t.ahk
#Include .\UTest.ahk
Return
Test_MyName() {
    Assert_True(MyName()="justjim")
}
#include .\mylib.ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2010, 3:23 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Fixed thx to Lexikos.

The problem was outdated version of LowLevel.ahk.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2010, 5:09 pm 
Offline

Joined: August 25th, 2010, 2:32 pm
Posts: 36
majkinetor wrote:
Fixed thx to Lexikos.

The problem was outdated version of LowLevel.ahk.


Thank you for the fix, it works great now. I enjoy reading your code, btw - right to the point, no more, no less.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2010, 9:09 am 
Offline
User avatar

Joined: January 25th, 2006, 8:08 am
Posts: 225
Location: Froschtümpel
Any change to make it work with AutoHotkey H 1.0.90.0 (I'm using Autohotkey_H 1.0.90.0 ?- rather than AutoHotKey_L)

Running your provided _test.ahk with AHK_H results in a dialogbox
Code:
Could not close previous instance of this script. Keep waiting? Yes|No


Pressing yes, the dialog box pops up again after a certain time, pressing No, your test script cancels ...

Works with AutoHotKey_L 1.0.90.0 ...


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], JamixZol, Yahoo [Bot] and 6 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group