Has anyone wrapped (almost) all AHK commands (for testing)?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Sticky
Posts: 10
Joined: 12 Apr 2017, 22:08

Has anyone wrapped (almost) all AHK commands (for testing)?

15 Sep 2021, 19:55

BRIEF: E.g. a class AHK_interface that has methods like send(...) and click(...) and sleep(...), with derived classes that do things like AHK_if_logging, AHK_if_cross_checking, AHK_if_perf, AHK_if_replay_testing, ...

---+ DETAIL:

I have written enough AutoHotKey code, and I depend on it so much[*], that I really need a better testing strategy. I am quite embarrassed at how little automated testing I have for the AutoHotKey code that I have written.

Of course, testing end to end, from a user hotkey to control of an application, is a bit of a challenge, given variation in screens and initial set up and timing and ... but that is of course why unit testing and subsystem testing was invented.

One of the standard techniques for unit and subsystem testing is to "wrapperize" a subsystem. To create a proxy, a stub. A standard technique with such a wrapper/stub/proxy is to record all the traffic across interface, and then when you are refactoring, making changes to code that should not change the functionality, test that the traffic across interface has not changed. That's easy enough for stuff I have written myself (well, it should be... I may have to clean my code up a little bit, use objects/classes better, ... )

But one of the most important set or system of interfaces that I would like to wrap and intercept is ... essentially all of the AutoHotKey commands.

Starting with "Send" and "Click", for when my AutoHotKey scripts control applications by sending them keyboard and mouse events. Progressing through "ExitApp". You start off by recording the output of such commands. eventually one intercepts things like "WinWait" and "WinWaitActive", so that the test harness can take the application windows to the code under test. And so on.

Before I start writing this, I wonder if anybody has already done it? no need to reinvent the wheel.

I realized while writing this that I should probably ask the more general question, of whether people have good end to end testing strategies for AutoHotKey. but that will be another post. In this post I only want to ask about wrapping all, or at least an important fraction, of the AutoHotKey interface: send, click, Win*, ClipWait...

If and when I start writing this I will probably just make an object-oriented interface that has methods like send(...) and click(...). object-oriented so that I can compose things like logging objects and running two versions of code in parallel and crosschecking. but I am not an object-oriented bigot, and I'm open to any form of wrapperization.


---

Note *: more and more I depend on AutoHotKey scripts because I invoke them from my Dragon speech recognition system. I mainly need to test AutoHotKey scripts used to control applications. I.e. AutoHotKey is no longer a convenience, the way it was when I first started using it, but AHK is now essential, at least until I decide to switch to some other scripting for speech commands.

While I would love to have end-to-end testing, for the moment I would be quite happy to have "refactoring testing", for open-loop scripts that just do things like always send a fixed stream of keyboard events to the target application(s) and operating system. Such open-loop scripts are fragile, as is any scripting system that emulates keyboard and mouse, and especially on systems that have strongly timing dependent behavior. But regression or refactoring testing, temporary exact testing, will help.
User avatar
Chunjee
Posts: 1418
Joined: 18 Apr 2014, 19:05
Contact:

Re: Has anyone wrapped (almost) all AHK commands (for testing)?

16 Sep 2021, 10:16

I wrote this simple testing library for testing outputs; https://github.com/Chunjee/unit-testing.ahk

Code: Select all

assert := new unittesting()

testVar := 2 + 2
assert.equal(testVar, 4)
assert.fullReport()
; => 1 test completed with 100% success (0 failures)
There is also https://github.com/Uberi/Yunit/blob/master/doc/Main.md which is more commonly used for testing.

Sadly I don't think either of these will test your keyboard or mouse output. You would need to figure out a way to measure those then cover them in the tests.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mmflume, ShatterCoder and 101 guests