 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Fri Sep 25, 2009 3:51 pm Post subject: [module] UTest v0.3 |
|
|
_________________

Last edited by majkinetor on Tue Sep 21, 2010 2:24 pm; edited 5 times in total |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 189 Location: Osnabrück, Germany
|
Posted: Sat Sep 26, 2009 10:08 am Post subject: |
|
|
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! |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Sat Sep 26, 2009 11:04 am Post subject: |
|
|
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. _________________
 |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 189 Location: Osnabrück, Germany
|
Posted: Sat Sep 26, 2009 2:27 pm Post subject: |
|
|
Thanks again,
Utest will be very useful (.. as much as all your other work)! |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Tue Dec 01, 2009 2:22 pm Post subject: |
|
|
*** version 0.2 ***
+ Added names and params.
+ Invalid tests are selected
+ Editor is open on double click
+ Docs improvements. _________________
 |
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Sun Aug 01, 2010 1:29 am Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Sun Aug 01, 2010 8:59 am Post subject: |
|
|
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. _________________
 |
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Sun Aug 01, 2010 2:29 pm Post subject: |
|
|
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' |
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Mon Aug 02, 2010 11:46 pm Post subject: |
|
|
| 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
}
|
|
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Tue Aug 03, 2010 1:00 am Post subject: |
|
|
| is it possible to add 'expected' and 'actual' columns to the listbox? |
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Mon Aug 23, 2010 5:03 am Post subject: |
|
|
| 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
}
|
|
|
| Back to top |
|
 |
justjim
Joined: 25 Aug 2010 Posts: 36
|
Posted: Tue Sep 21, 2010 8:01 am Post subject: |
|
|
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
|
|
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Tue Sep 21, 2010 2:23 pm Post subject: |
|
|
Fixed thx to Lexikos.
The problem was outdated version of LowLevel.ahk. _________________
 |
|
| Back to top |
|
 |
justjim
Joined: 25 Aug 2010 Posts: 36
|
Posted: Tue Sep 21, 2010 4:09 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
hoppfrosch
Joined: 25 Jan 2006 Posts: 190 Location: Froschtümpel
|
Posted: Wed Dec 08, 2010 8:09 am Post subject: |
|
|
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 ... |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|