Trouble using utest.Assert

I would like to profit from the utest.Assert methods. Currently I just want to write very small lightweight tests, however it seems using Assert is not intended that way? Maybe only works inside a TestCase and that must “extend utest.Test or implement utest.ITest.” (from the file). Anyway here’s some sample:

import utest.*;

class MyClass {
    public static function main() {
        Assert.equals( true, true );

-lib utest
-main MyClass
-hl test.hl

But from that I get (using HashLink):

MyClass.hx:5: start
Uncaught exception: Assert at MyClass.hx:6 out of context. Most likely you are trying to assert after a test timeout.
Called from utest.$Assert.equals(utest/Assert.hx:141)
Called from $MyClass.main(MyClass.hx:6)
Called from fun$470(?:1)

Is there a way to just profit from the utest.Assert alone without the whole utest setup stuff? I mean the class Assert says “used to perform assertations inside a test method.” (github) Maybe that refers to TestCase only, irdk…

Thank you. :slight_smile:

Yeah, utest.Assert is not intended for a standalone usage.

1 Like

You can probably trick it by manually handling Assert.results like this:

Assert.results = new List();
//do your tests
for(result in Assert.results) {
  switch result {
    case Failure(msg, pos): //handle failures here
    case Success(pos):
    case _: //this case probably won't happen outside of a propert utest setup
1 Like

This works well. Thank you! :smiley: