Simple unit testing class to perform and report tests for AutoHotkey projects
npm install unit-testing.ahkunit-testing.ahk
===========
A unit test framework for AutoHotkey
bash
npm install unit-testing.ahk
`
In your code:
`autohotkey
#Include %A_ScriptDir%\node_modules
#Include unit-testing.ahk\export.ahk
assert := new unittesting.ahk
testVar := 2 + 2
assert.equal(testVar, 4)
assert.fullReport()
`
You may also review or copy the library from ./export.ahk on GitHub; #Include as you would normally when manually downloading.
Usage
Grants access to a class named unittesting with the following methods: .equal, .true, .false, .notEqual, .label, .report, .fullReport, and .writeTestResultsToFile
`autohotkey
assert := new unittesting()
; .equal checks and logs whether or not both arguments are the same
assert.label("string comparison")
assert.equal("StringExample", "StringExample")
assert.label("value testing")
assert.equal((1 > 0 ), true)
assert.label("true/false testing")
assert.true((1 == 1))
assert.false((1 != 1))
assert.notEqual(true,false)
assert.report()
assert.fullReport()
assert.writeTestResultsToFile()
`
API
$3
Alias: .test
checks if actual and expected are the same or equal. The comparison is case-insensitive when ahk is inStringCaseSense, Off (default ahk behavior)
##### Arguments
1. actual (*): The actual value computed
2. expected (*): The expected value
##### Returns
(boolean): returns true if the values were the same, else false
##### Example
`autohotkey
assert.equal("string", "tsring")
; => false
assert.equal((1 > 0 ), true)
; => true
`
$3
checks if actual value is true.
##### Arguments
1. actual (*): The actual value computed
##### Returns
(boolean): returns true if the value is true, else false
##### Example
`autohotkey
assert.true((1 == 1))
; => true
assert.true(InStr("String", "S"))
; => true
`
$3
checks if actual value is false.
##### Arguments
1. actual (*): The actual value computed
##### Returns
(boolean): returns true if the value is false, else false
##### Example
`autohotkey
assert.false((1 != 1))
; => true
assert.false(InStr("String", "X"))
; => true
`
$3
checks if actual and expected are NOT the same or equal. The comparison is case-insensitive when ahk is inStringCaseSense, Off (default ahk behavior)
##### Arguments
1. actual (*): The actual value computed
2. expected (*): The expected value
##### Returns
(boolean): returns true if the value is false, else false
##### Example
`autohotkey
assert.false((1 != 1))
; => true
assert.false(InStr("String", "X"))
; => true
`
$3
checks if actual is undefined ("").
##### Arguments
1. actual (*): The actual value computed
##### Returns
(boolean): returns true if the value is "", else false
##### Example
`autohotkey
assert.false((1 != 1))
; => true
assert.false(InStr("String", "X"))
; => true
`
$3
labels the following tests for logs and readability
##### Arguments
1. label (string): A human readable label for the next test(s) in sequence
##### Example
`autohotkey
assert.label("string comparisons")
assert.equal("String", "s")
assert.fullReport()
/*---------------------------
1 tests completed with 0% success (1 failure)
=================================
== string comparisons ==
Test Number: 1
Expected: s
Actual: String
---------------------------*/
`
$3
Uses msgbox to display the results of all tests
##### Example
`autohotkey
assert.true(InStr("String", "S"))
assert.report()
/*---------------------------
1 test completed with 100% success
---------------------------*/
`
$3
Uses msgbox to display the results of all tests with details of any failures
##### Example
`autohotkey
assert.true(InStr("String", "X"))
assert.fullReport()
/*---------------------------
1 tests completed with 0% success (1 failure)
=================================
Test Number: 1
Expected: true
Actual: false
---------------------------*/
`
$3
writes test results to a file
##### Arguments
1. filepath (string): Optional, The file path to write all tests results to, the default is A_ScriptDir "\result.tests.log"
##### Example
`autohotkey
assert.true(InStr("String", "X"))
assert.writeTestResultsToFile()
/*Test Number: 1
Expected: true
Actual: false*/
``