Would seriously appreciate some help getting off the ground with munit

Ok, so I’ve installed munit, it runs, I followed the tutorial about setting it up, I have some files in my haxe lib’s root folder.


haxelib run munit test
Massive Unit - Copyright 2019 Massive Interactive. Version src
   haxe -main TestMain -lib munit -lib hamcrest -cp src/nexus/tests -cp src/nexus/tests -swf-version 11 -swf build/as3_test.swf
   Invalid commandline class : TestMain should be nexus.tests.TestMain
C:\HaxeToolkit4\haxe\lib\hamcrest/2,0,1/org/hamcrest/Exception.hx:10: characters 18-26 : name: Custom property accessor is no longer supported, please use `get`
C:\HaxeToolkit4\haxe\lib\hamcrest/2,0,1/org/hamcrest/Exception.hx:13: characters 21-32 : message: Custom property accessor is no longer supported, please use `get`
C:\HaxeToolkit4\haxe\lib\hamcrest/2,0,1/org/hamcrest/Exception.hx:16: characters 19-28 : cause: Custom property accessor is no longer supported, please use `get`
src/nexus/tests/TestSuite.hx:3: characters 8-19 : Invalid package : <empty> should be nexus.tests
Error: Error compiling hxml for as3
Target as3 C:\Dropbox (MAxonn)\Coding\Nexus\Kod\NexusDK\build\as3_test.swf

test.hxml has this in it:

## Flash 9+
-main TestMain
-lib munit
-lib hamcrest
-cp src/nexus/tests

-cp src/nexus/tests
-swf-version 11
-swf build/as3_test.swf

## JavaScript
--next
-main TestMain
-lib munit
-lib hamcrest
-cp src/nexus/tests

-cp src/nexus/tests
-js build/js_test.js

## Neko
--next
-main TestMain
-lib munit
-lib hamcrest
-cp src/nexus/tests

-cp src/nexus/tests
-neko build/neko_test.n

## CPP
--next
-main TestMain
-lib munit
-lib hamcrest
-cp src/nexus/tests

-cp src/nexus/tests
#-D HXCPP_M64
-cpp build/cpp_test

## Java
--next
-main TestMain
-lib munit
-lib hamcrest
-cp src/nexus/tests

-cp src/nexus/tests
-java build/java_test

## CSharp
--next
-main TestMain
-lib munit
-lib hamcrest
-cp src/nexus/tests

-cp src/nexus/tests
-cs build/cs_test

## Python
--next
-main TestMain
-lib munit
-lib hamcrest
-cp src/nexus/tests

-cp src/nexus/tests
-python build/python_test.py

## PHP 7
--next
-main TestMain
-lib munit
-lib hamcrest
-cp src/nexus/tests

-cp src/nexus/tests
-D php7
-php build/php_test

## JavaScript NodeJS
--next
-main TestMain
-lib munit
-lib hamcrest
-lib hxnodejs
-cp src/nexus/tests

-cp src/nexus/tests
-js build/js_test.js

## HashLink
--next
-main TestMain
-lib munit
-lib hamcrest
-cp src/nexus/tests

-cp src/nexus/tests
-hl build/hl_test.hl

I have the TestMain, TestSuite and ExampleTest just how the configure command of munit created them after specifying a target source.

This is the .munit file

version=src
src=src/nexus/tests
bin=build
report=report
hxml=test.hxml
classPaths=src

Thank you for reading and helping me. I promise I’ll make manual entries about whatever thing worthy I can muster :slight_smile:

Ok, I think I managed it a bit further. I imported the lib in IntelliJ and also referred to the following modules which it seems to need (most of which I had to manually install): mlib, asynctools.

I’m targeting Flash, and it does produce a SWF file, but when I try to open it it fails with “call to external interface failed”.

I also tried setting JS as a target for this project. It produces a JS file but upon including it in an index and serving that file, it complains that MissingElementException: haxe.trace element not found at massive.munit.client.ExternalPrintClientJS#new(275)

Hello, unfortunately hamcrest is unmaintained and hasn’t been adapted to Haxe 4.
munit and mlib were very recently released with Haxe 4 support.

Output of the test.hxml compilation can’t be just executed - it has to be run by munit. The tool sets up a server and runs each platform in way allowing all the results to be aggregated.

Errors indicate that somehow the /src classpath is considered as the compilation root. Is by any chance /src the root of your code otherwise? You may have more success moving your tests under /test to be in a different folder than your sources.

Hey Philippe and thanks for answering :slight_smile:. I just recently realized you are involved in some of the massive work Massive has been doing with Haxe :wink: . The more (not necessarily financial) wealth can be generated using Haxe, the better we’ll all be. I’m working on contributing to that wealth :slight_smile:.

I have reconfigured munit using the haxelib run munit config -reset command and now the test folder is a sibling of src. I still get the hamcrest error when I run haxelib run munit test. I’ve been following this tutorial:

I still get the same hamcrest errors. I’ve tried to identify how hamcrest is used. I saw that in TestRunner.hx there is a compilation directive related to it. Is there a compilation flag that I can use to avoid using hamcrest? Since you mentioned munit and mlib were updated for Haxe 4, I assume we can unit test with munit on Haxe 4 :slight_smile:

for Hamcrest and Haxe 4 you need a patched version, try:
haxelib git hamcrest https://github.com/kaikoga/hamcrest-haxe patch-haxe4-p5 src

Thank you @ablum! :slight_smile:. This got me a bit further. I was now able to run the tests, however, neko.exe seems to have a problem. It hands, hogging 1 CPU core for 100% for a while, after which the command line crashes. I see no test results in my browser, obviously.

Massive Unit - Copyright 2019 Massive Interactive. Version src
   haxe -main TestMain -lib munit -lib hamcrest -cp src -cp src/test -js build/js_test.js
   haxe -main TestMain -lib munit -lib hamcrest -lib hxnodejs -cp src -cp src/test -js build/js_test.js

MUnit Results
------------------------------
Class: ExampleTest ..
==============================
PASSED
Tests: 2  Passed: 2  Failed: 0 Errors: 0 Ignored: 0 Time: 0.208

Tests PASSED under js using summary client
------------------------------
PLATFORMS TESTED: 1, PASSED: 1, FAILED: 0, ERRORS: 0, TIME: 30.76
------------------------------
ERROR: Local results server appeared to hang so test reporting was cancelled.

I tried the JS target too, after installing hxnodejs. Same thing happened.