Skip to content

Unit Tests

m0rkeulv edited this page Oct 25, 2026 · 4 revisions

Run and debug your Haxe unit tests from the editor gutter, the Haxe tool window or a run configuration. Results appear in IntelliJ IDEA's test runner as a tree, and you can jump from a test to its source. This page covers the supported frameworks, how the plugin finds your tests and the targets the tests can run on.

Note

Beta. Unit test support works and is supported, but may still change.

Supported frameworks

Framework Library What the plugin recognizes as a test
utest utest A class that extends utest.Test or implements utest.ITest, also through your own base class. Each non-static method whose name starts with test or spec is a test.
munit munit A class with at least one method tagged @Test or @AsyncTest. Its tagged public, non-static methods are tests.
tink_unittest tink_unittest A class tagged @:asserts. Each public, non-static method of that class is a test, except the setup and teardown methods (@:setup, @:startup, @:before, @:after, @:teardown, @:shutdown) and methods tagged @:exclude.
buddy buddy No single tests: buddy specs are describe and it blocks, not methods, so buddy tests always run as a whole.

The plugin picks the framework from the libraries that your tests build file declares (see the next section): -lib utest in an hxml file, or <haxelib name="utest" /> in a Lime or OpenFL project file. Declare the framework library directly in that file. A framework that only comes in as a dependency of another library is not detected.

For the versions of each framework, see Supported Versions.

Tests build files

Test runs compile and launch a tests build file: a build file that builds your tests. It declares the test framework library, the class paths of your tests and of the code they test, a main class that runs the tests, and the target to run them on.

A build file becomes a tests build file in one of two ways:

  • Automatically, when it declares a test framework library and either is named test.hxml or tests.hxml, or is inside a folder named tests within the module.
  • By marking it: in the Haxe tool window, right-click the build file and choose Mark as Tests Build File. This entry is only offered for build files that declare a test framework library.

To stop treating a file as a tests build file, right-click it and choose Unmark as Tests Build File. This also works for files that were detected automatically, which then stay unmarked, and for a marked file that no longer declares a test framework library.

A tests build file shows (Tests) after its name in the tool window and gets a Tests group with a Run Unit Tests entry. Its libraries are added to the module's libraries, so your test code resolves in the editor. When you mark a file whose class path folders are not source folders yet, the plugin asks in the Configure Folders from Build File dialog whether to mark them. Answer Yes, so that breakpoints in your tests work.

Tests build files can be hxml files or Lime/OpenFL project files. NME project files (.nmml) can only run the whole tests build. In an hxml file with several --next sections, test runs use the section selected in the tool window. In a Lime, OpenFL or NME project file, they use the selected target. See Targets and Sections and Build Files.

Example

A small project with utest tests:

my-app/
  build.hxml
  src/Calculator.hx
  test/CalculatorTest.hx
  test/TestMain.hx
  test.hxml

test.hxml:

-cp src
-cp test
-lib utest
--main TestMain
--interp

test/TestMain.hx:

class TestMain {
  static function main() {
    utest.UTest.run([new CalculatorTest()]);
  }
}

test/CalculatorTest.hx:

import utest.Assert;

class CalculatorTest extends utest.Test {
  function testAdd() {
    Assert.equals(4, new Calculator().add(2, 2));
  }
}

The file is named test.hxml and declares utest, so it is a tests build file without marking. --interp runs the tests in the Haxe interpreter, the quickest way to start. For other targets, see Where tests can run.

Run tests

From the Haxe tool window

  1. Open the Haxe tool window.
  2. Expand the tests build file and its Tests group.
  3. Double-click Run Unit Tests. To debug, right-click it and choose Debug Unit Tests.

A tests build file in the Haxe tool window, with Run Unit Tests in its Tests group

The Tests group of a tests build file

You can also right-click a module, or the project, and choose Run Unit Tests or Debug Unit Tests. This runs the module's first tests build file. If the module has no tests build file, Run Unit Tests is disabled.

From the editor gutter

Test classes and test methods get a run marker in the gutter when their file is in one of the tests build file's class paths (-cp in an hxml file, <source path> in a Lime/OpenFL project file). Click the marker and choose Run or Debug, for example Run 'CalculatorTest'. A marker on a class runs that class; a marker on a method runs that single test.

Run markers in the gutter beside a test class and its test method

The run markers of a test class and its test method

Gutter markers are available for utest, munit and tink_unittest, in hxml and Lime/OpenFL tests build files.

If several tests build files include the same file, the markers use one of them, and files you marked come before automatically detected ones. To run the tests on another target, use that build file's Run Unit Tests entry.

From a context menu

Right-click a test class or test method in the editor, or one or more files or folders in the Project view, and choose the Run entry for it. The plugin runs every test class it finds in the selection. Several files or folders run together when they belong to the same tests build file.

A folder works when it is one of the tests build file's class paths, or inside one. A folder above the class paths, such as my-app in the example above, offers no run. Context-menu runs are available for the same frameworks and build files as gutter markers.

How runs of single classes and tests work

To run only some classes, or a single test, the plugin compiles the tests build file with a generated main class in place of yours. That generated main runs only your selection.

  • Code in your own test main does not run for these runs.
  • The generated main creates each selected utest or tink_unittest class with new ClassName(), so these classes need a constructor without arguments.
  • For an hxml tests build file, the output goes to a temporary folder, so the output of your full tests build is not overwritten.
  • A Lime/OpenFL tests build file is built with its tool as usual, with the generated main replacing the app's main class.

Run configurations

Every run creates or reuses a Haxe Unit Tests run configuration and selects it in the run configuration list on the toolbar, so you can run it again from there. Its name follows what it runs, for example Unit Tests (test.hxml), CalculatorTest (test.hxml), CalculatorTest.testAdd (test.hxml) or Tests in 'test'.

To create one yourself, open Run | Edit Configurations…, add a Haxe Unit Tests configuration and fill in:

Field Meaning
Tests build file: The build file to compile and run. The list shows all build files of the project.
Test filter pattern: utest only. A regular expression: only tests whose full name (package.ClassName.testName) contains a match run. The plugin passes it to utest as -D UTEST_PATTERN=<pattern>. Other frameworks ignore it. It also narrows a class run started from the gutter or a context menu. A single-test run does not use it, and the field is disabled there.
Runs: Shown for a configuration created from the gutter or a context menu: the classes or the single test it runs.

See Run Configurations for the other run configuration types.

The compile step

flowchart LR
    start(["Run Unit Tests,<br/>gutter or context menu"])
    compile["Compile the tests build file,<br/>plus the plugin's reporter"]
    run["Run on<br/>the target"]
    tree["Results tree"]
    single["Single classes or tests: a<br/>generated main replaces yours"]
    start --> compile --> run
    run -->|"reporter output"| tree
    single -.-> compile
Loading

For every target except the interpreter, a Haxe Unit Tests configuration has a Run Haxe action step under Before launch. This step compiles the tests build file together with the plugin's test reporter (see If no results appear) and shows its output in the Build tool window. The tests start when it succeeds. The plugin updates this step itself when the build file, its selected target or section, or the test settings change. It replaces only its own step: other Before launch tasks you add are kept, and a compile step you remove comes back.

With the interpreter, compiling and running are one step, and compiler errors appear in the test console.

The compile step uses the compilation server when it is enabled for the module (see Compilation Server). Interpreter runs never use it, because the tests have to run in their own process. Test runs compile and run your project's code, so they need a trusted project (see Core Concepts).

Where tests can run

hxml tests build files

Target in the tests build file How the tests run You need
--interp, or no target Compiled and run in one step by the Haxe interpreter Nothing extra. munit tests cannot run here.
-hl tests.hl HashLink runs the bytecode HashLink: the HashLink executable: under Runtime Overrides in Build Tools | Haxe, else the Haxe SDK's HashLink executable:, else the HASHLINK_BIN, HASHLINK or HASHLINKPATH environment variable, else hl on the PATH
-neko tests.n Neko runs the bytecode Neko
--jvm tests.jar java -jar runs the jar java on the PATH
-cpp bin The built executable runs A C++ toolchain, and a --main class in the build file: the executable is named after it
-js tests.js Node.js runs the script Node.js, from Build Tools | Haxe, the Haxe SDK or the PATH. Add -lib hxnodejs (or -D nodejs) for correct reporting and exit codes; without it the run still starts and shows a hint.
-swf tests.swf The AIR SDK's adl runs the SWF in a hidden window A Flex/AIR SDK (see below). buddy tests cannot run here.

Other outputs cannot run tests: HashLink/C (-hl to a .c file), Java sources (--java), C#, PHP, Python, Lua and cppia. A run on one of them stops with an error that lists the supported targets.

For Flash tests, select a Flex/AIR SDK for the Haxe SDK or under Settings | Build, Execution, Deployment | Build Tools | Haxe, or set the AIR_SDK environment variable to the SDK folder. To install the runtimes, see Installation.

Lime, OpenFL and NME tests build files

The compile step builds the selected target with the Lime, OpenFL or NME tool. The plugin then launches the packaged app.

Selected target How the tests run
neko, cpp, windows, mac, linux The packaged app runs.
hl (Lime/OpenFL) The packaged app runs with the HashLink runtime bundled with it.
flash, and air (Lime/OpenFL) The AIR SDK's adl runs the SWF, as for hxml files.
html5 (Lime/OpenFL) The plugin serves the packaged output and opens it in a Chromium-family browser.

Other targets, such as android or ios, cannot run tests.

An html5 run needs:

  • a Chromium-family browser as the first active browser under Settings | Tools | Web Browsers and Preview, with the full path of its executable set;
  • Node.js 18 or later, and the js-debug adapter (Chromium, Node.js) downloaded once from a Haxe Web Browser or Node.js Application run configuration (see Debugging JavaScript).

The run ends when the tests report that they are finished. If the page prints nothing for 120 seconds, the run stops with an error.

Debug tests

Start a debug run with Debug Unit Tests in the Haxe tool window, with Debug on a gutter marker or by debugging a Haxe Unit Tests configuration. For a debug run, the plugin compiles the tests with the target's debug arguments. Breakpoints in your test code work, and the results tree fills in the Debug tool window as usual.

Target What you need More
Interpreter Nothing extra Debugging with the Interpreter
HashLink (hxml -hl, Lime/OpenFL hl) For hxml, a HashLink runtime, found as for running. A Lime/OpenFL build uses its bundled runtime. Debugging HashLink
C++ (desktop) The intellij-hxcpp-debug-server library. If it is missing, a notification offers Install. Debugging HXCPP
JavaScript run by Node.js Node.js 18 or later, and the js-debug adapter (Chromium, Node.js), downloaded once from a Haxe Web Browser or Node.js Application run configuration Debugging JavaScript
Flash and AIR IntelliJ IDEA Ultimate with the Flash/Flex plugin, and a Flex/AIR SDK registered in the IDE Debugging Flash and AIR

Neko and JVM tests cannot be debugged. For them, Debug Unit Tests and the gutter's Debug entry are disabled.

Tip

If breakpoints in your tests are not hit, check that the folders with your test sources are source folders of the module. When you mark a tests build file, the Configure Folders from Build File dialog sets this up.

Test results

Results appear in the Run tool window, or the Debug tool window when you debug. The tree starts with a node named after the target, for example "Target: HashLink", followed by your test classes and their tests.

The test results tree with a Target: HashLink node above the test classes

A passed test run on HashLink

Framework When results appear Good to know
utest While the tests run, with Live test reporting on (the default). With it off, at the end of the run. utest gives a test without assertions a warning. The tree shows that test as failed, with the warning as its message.
munit As each test finishes Tests tagged @Ignore show as ignored.
tink_unittest As each test finishes No durations. Tests excluded with @:exclude do not appear.
buddy All at once, when the run ends describe blocks show as suites; pending specs show as ignored.

With utest, munit and buddy, the output that a test prints with trace appears under that test. Select a test to see its output.

To open a test's source, double-click it in the tree. A class or test opens at its declaration. A buddy spec opens at its description text in the file that declares it. See Explore test results in the IntelliJ IDEA documentation for the test runner itself.

To run the tests again, rerun the configuration from the Run tool window or the toolbar. There is no action that reruns only the failed tests.

Live test reporting

Settings | Build, Execution, Deployment | Build Tools | Haxe has a Tests group with the Live test reporting option. It is on by default and affects utest only:

  • On: utest results appear while the tests run. If your utest version does not support this, the run falls back to utest's end-of-run report by itself.
  • Off: results appear when the run ends.

In Flash, AIR and html5 test runs, utest results always appear while the tests run, whatever this option says. Changing the option also updates your existing Haxe Unit Tests configurations. See Settings Reference for the other options on that settings page.

If no results appear

The IDE reads test results from the output of the test process. To produce that output, the plugin adds a small reporter, written in Haxe, to the test compile, and your Haxe compiler builds it together with your tests. The reporter compiles with Haxe 3.4.7 and later. Your files are not changed, and builds you start outside of test runs do not include the reporter.

If a run finishes but the results tree stays empty and the test output shows only in the console, check how your test main starts the tests:

  • utest: utest's own report comes from utest.ui.Report.create(runner), which utest.UTest.run calls for you. If your main creates a different report and Live test reporting is off, the results tree stays empty.
  • tink_unittest: call Runner.run(batch) without a reporter argument. A reporter that you pass yourself replaces the plugin's, and the results tree stays empty.
  • buddy: the plugin's reporter is used by the main class that buddy generates for you (for a class that extends buddy.SingleSuite or implements buddy.Buddy). If your own code creates buddy's runner, as a Lime, OpenFL or NME test app must, you see console output only.

Jump between a class and its test

Use Navigate | Test in a class to jump to its test, and Navigate | Test Subject in a test to jump back. The plugin matches by name: the test of Calculator is CalculatorTest or TestCalculator. See Navigate between tests and test subjects in the IntelliJ IDEA documentation.

Limitations

  • buddy tests run only as a whole tests build: no gutter markers, no context-menu runs and no single specs.
  • Test filter pattern: works for utest only.
  • NME tests build files run only as a whole.
  • munit tests cannot run on the interpreter, and buddy tests cannot run on Flash or AIR.
  • tink_unittest classes without @:asserts get no gutter markers. They still run as part of the whole tests build.
  • There is no action that reruns only the failed tests.
  • Neko and JVM tests cannot be debugged.

Clone this wiki locally