Giter Club home page Giter Club logo

unit-testing.ahk's Introduction

unit-testing.ahk

A unit test framework for AutoHotkey

Installation

In a terminal or command line navigated to your project folder:

npm install unit-testing.ahk

In your code:

#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, .notEqual, .true, .false, .label, .group, .report, .fullReport, and .writeTestResultsToFile

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

.equal(actual, expected)

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
assert.equal("string", "tsring")
; => false

assert.equal((1 > 0 ), true)
; => true

.true(actual)

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
assert.true((1 == 1))
; => true

assert.true(InStr("String", "S"))
; => true

.false(actual)

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
assert.false((1 != 1))
; => true

assert.false(InStr("String", "X"))
; => true

.notEqual(actual, expected)

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
assert.notEqual((1 != 1))
; => true

assert.notEqual(InStr("String", "X"))
; => true

.undefined(actual)

checks if actual is undefined ("").

Arguments
  1. actual (*): The actual value computed
Returns

(boolean): returns true if the value is "", else false

Example
assert.false((1 != 1))
; => true

assert.false(InStr("String", "X"))
; => true

.label(label)

labels the following tests for logs and readability

Arguments
  1. label (string): A human readable label for the next test(s) in sequence
Example
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
---------------------------*/

.group(label)

appends the label to a group of following tests for logs and readability

This may be useful when one has a lot of tests; and doesn't want to type out a repeatative label

Arguments
  1. label (string): A human readable label prepend for the next test(s) in sequence
Example
assert.group("strings")
assert.label("comparison")
assert.equal("String", "s")

assert.label("length")
assert.equal(strLen("String"), 9)

assert.fullReport()
/*---------------------------
2 tests completed with 0% success (2 failures)
=================================
== strings - comparisons ==
Test Number: 1
Expected: s
Actual: String

== strings - length ==
Test Number: 2
Expected: 99
Actual: 6
---------------------------*/

.report()

Uses msgbox to display the results of all tests

Example
assert.true(InStr("String", "S"))

assert.report()
/*---------------------------
1 test completed with 100% success
---------------------------*/

.fullReport()

Uses msgbox to display the results of all tests with details of any failures

Example
assert.true(InStr("String", "X"))

assert.fullReport()
/*---------------------------
1 tests completed with 0% success (1 failure)
=================================
Test Number: 1
Expected: true
Actual: false
---------------------------*/

.writeResultsToFile([filepath, fileopen])

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"

  2. fileopen (bool): Optional, Open the file if true. Default: false

Example
assert.true(InStr("String", "X"))

assert.writeTestResultsToFile()
/*
1 test completed with 0% success (1 failure)

Test Number: 1
Expected: true
Actual: false*/

unit-testing.ahk's People

Contributors

chunjee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.