UTest

Unit testing framework.

Usage

UTest will scan the script for functions which name starts with “Test_”.  Test functions have no parameter and use one of the Assert functions.  If Assert function fails, test will fail and you will see that in the result CSV (or in ListView representing that CSV).  Result shows the the test state, the function name, line number and test name if you have it.

To test your script, use the following template :

#include UTest.ahk
return

Test_MyTest1() {
}

Test_MyTest2() {
}
...
...
#include FunctionToTest.ahk

Remarks

By default, executing the test script will show the GUI with the results.  To get the same results in textual form you can set NoGui option and query Result variable from UTest storage:

UTest("NoGUI", true)
#include UTest.ahk
msgbox  UTest("Result")

CSV

ResultTest result (OK | FAIL).
TestTest function name.
LineLine number of the test.
NameList of names that failed.  Name is the Assert user label.  Give name to the Assert function if you have multiple Assert functions inside single test.
ParamList of parameters which failed (Assert_True, Assert_False)

Aditionally, if you use Gui, tests that failed will be selected and if any of the test failed, complete operation will be marked as failed at the bottom of the gui.

Summary
UTestUnit testing framework.
Assert_TrueCheck if conditions are true.
Assert_FalseCheck if conditions are false.
Assert_EmptyCheck if variable is empty.
Assert_NotEmptyCheck if variable is not empty.
Assert_ContainsCheck if variable contains string.
Assert_StartsWithCheck if variable starts with string.
Assert_EndsWithCheck if variable ends with string.
Assert_MatchCheck if variable content matches RegEx pattern.
UTest_EditOpen editor with given file and go to line number.
About

Assert_True

Assert_True(b1 = "",
b2 = "",
b3 = "",
b4 = "",
b5 = "",
b6 = "",
b7 = "",
b8 = "",
b9 = "",
b10 = "")

Check if conditions are true.  All parameters must be expressions except the first one which may be the string representing the test name.

Assert_False

Assert_False(b1 = "",
b2 = "",
b3 = "",
b4 = "",
b5 = "",
b6 = "",
b7 = "",
b8 = "",
b9 = "",
b10 = "")

Check if conditions are false.  All parameters must be expressions except the first one which may be the string representing the test name.

Assert_Empty

Assert_Empty(Var,  
Name = "")

Check if variable is empty.

Assert_NotEmpty

Assert_NotEmpty(Var,  
Name = "")

Check if variable is not empty.

Assert_Contains

Assert_Contains(Var,  
String,  
Name = "")

Check if variable contains string.

Assert_StartsWith

Assert_StartsWith(Var,  
String,  
Name = "")

Check if variable starts with string.

Assert_EndsWith

Assert_EndsWith(Var,  
String,  
Name = "")

Check if variable ends with string.

Assert_Match

Assert_Match(Var,  
RegEx,  
Name = "")

Check if variable content matches RegEx pattern.

UTest_Edit

UTest_Edit(Path,
LineNumber)

Open editor with given file and go to line number.  Required to be implemented by the user in order for double click in GUI to work.

About

Assert_True(b1 = "",
b2 = "",
b3 = "",
b4 = "",
b5 = "",
b6 = "",
b7 = "",
b8 = "",
b9 = "",
b10 = "")
Check if conditions are true.
Assert_False(b1 = "",
b2 = "",
b3 = "",
b4 = "",
b5 = "",
b6 = "",
b7 = "",
b8 = "",
b9 = "",
b10 = "")
Check if conditions are false.
Assert_Empty(Var,  
Name = "")
Check if variable is empty.
Assert_NotEmpty(Var,  
Name = "")
Check if variable is not empty.
Assert_Contains(Var,  
String,  
Name = "")
Check if variable contains string.
Assert_StartsWith(Var,  
String,  
Name = "")
Check if variable starts with string.
Assert_EndsWith(Var,  
String,  
Name = "")
Check if variable ends with string.
Assert_Match(Var,  
RegEx,  
Name = "")
Check if variable content matches RegEx pattern.
UTest_Edit(Path,
LineNumber)
Open editor with given file and go to line number.
Close