[a138+] UnitTest-Framework? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

[a138+] UnitTest-Framework?

30 Jun 2021, 08:06

Hi there,

has already somebody a simple UnitTest-framework for a138?

@lexikos: Do you still use a own version of Uberi's YUnit (https://github.com/Uberi/Yunit) - and are willing to share it?
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: [a138+] UnitTest-Framework?  Topic is solved

02 Aug 2021, 21:51

hoppfrosch wrote:
30 Jun 2021, 08:06
has already somebody a simple UnitTest-framework for a138?
i think i finally got this figured out for v2beta1

please check it and test it out for any bugs:

https://github.com/Uberi/Yunit/tree/v2

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: [a138+] UnitTest-Framework?

06 Aug 2021, 22:05

I kept this topic open on my phone and was reminded to reply several times over the last month, but of course, always while using my phone and not being in a position to type a proper reply.

I had only been updating the core part of Yunit (Yunit.ahk) and had not bothered with version control.

Yunit is described as "super simple", but for how I use it, it is over-engineered. I tried the GUI at first and quickly found that it wasn't useful to me; I prefer to have the tests print to the editor's output pane and immediately exit. Using the Yunit class directly was inconvenient, so I've been using shortcut functions since early on. My test scripts generally consist of:
  • tests followed by a list of classes.
  • Tests defined as methods of classes. The methods are generally self-contained; I generally do not use __new/__delete, Begin/End, or ExpectedException.
  • A series of related assertions with assert expression, throws ()=> expression (which passes only if the expression throws an exception) and equals expression, value.
The helper functions were defined like this:

Code: Select all

tests(t*) => Yunit.Use(YunitStdOut).Test(t*)
assert(p*) => Yunit.Assert(p*)
equals(a, b) => assert(a == b, (a is Number ? a : '"' a '"') ' != ' (b is Number ? b : '"' b '"'))
throws(f, p*) {
    try f()
    catch
        return
    assert(false, p*)
}
Although I actually use a replacement for YunitStdOut which changes the format slightly.

After thinking about what Yunit actually does that I use, I worked out that the following was sufficient to replace it for my existing tests:

Code: Select all

tests(classes*) {
    for testclass in classes {
        env := testclass()
        for name in ObjOwnProps(testclass.Prototype) {
            if SubStr(name, 1, 2) != '__' {
                try
                    env.%name%()
                catch as e
                    print "FAIL: " type(env) "." name errline(e)
                else
                    print "PASS: " type(env) "." name
            }
        }
    }
    errline(e) => "`n" StrReplace(e.File, A_InitialWorkingDir "\") " (" e.Line ") : " e.Message
    print(s) => FileAppend(s "`n", "*")
}

assert(condition, message:="FAIL", n:=-1) {
    if !condition
        throw Error(message, n)
}

equals(a, b) => assert(a == b, (a is Number ? a : '"' a '"') ' != ' (b is Number ? b : '"' b '"'), -2)

throws(f, m:="FAIL (didn't throw)") {
    try f()
    catch
        return
    assert(false, m, -2)
}
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: [a138+] UnitTest-Framework?

22 Sep 2021, 02:11

@guest3456 - thanks for the update of YUnit. Started using it ...

@lexikos - will have a look into it.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: hiahkforum, kingina, niCode, w_i_k_i_d and 61 guests