Run unit tests with Apache Ant

Add a custom task for RoyaleUnit to your Apache Ant build files

Activate the RoyaleUnit Ant task

First, we need to add a <taskdef> to make the <royaleunit> task available for use in our build file:

<taskdef resource="royaleUnitTasks.tasks" classpath="${royalesdk}/js/lib/royaleUnitTasks.jar"/>

Replace the ${royalesdk} token with the path to the Apache Royale SDK on your computer.

Run unit tests in HTML and JavaScript

To run unit tests for JavaScript with a web browser, set the player attribute to either "chromium", "webkit", or "firefox". Or you can set it to "html", if you don’t have a browser preference. This tells the Ant task to use Playwright to launch a headless browser that connects to using WebSockets. Set the swf attribute to the path to an .html file:

<royaleunit player="webkit" swf="${basedir}/bin/js-debug/index.html"/>

In the example above, we point to the index.html file generated by the Apache Royale compiler in bin/js-debug, and we specifiy that the tests should be run in WebKit.

Custom browser executable

By default, Ant will run the unit tests in a headless browser powered by Playwright. To run using a specific browser executable, you may specify the executable’s path using the command attribute.

In Royale 0.9.9 and older, Playwright was not yet supported, and Ant would launch the tests in your system’s default web browser, when no command executable is specified.

In the following example, we’ll run unit tests in Google Chrome.

On Windows, set the command to an .exe file:

<royaleunit player="html" swf="path/to/file.html"
	command="c:/Program Files/Google/Chrome/Application/chrome.exe"/>

On macOS, set the command to the executable inside an .app package:

<royaleunit player="html" swf="${basedir}/bin/js-debug/index.html"
	command="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"/>

If you need to pass arguments to the executable, set the commandArgs attribute:

<royaleunit player="html" swf="path/to/file.html"
	command="c:/Program Files/Google/Chrome/Application/chrome.exe"
	commandArgs="--no-sandbox --user-data-dir=custom_chrome_profile --no-first-run"/>

Run unit tests in Adobe Flash Player

To run unit tests with Adobe Flash Player, set the player attribute to "flash". Set the swf attribute to the path of a .swf file:

<royaleunit player="flash" swf="bin-debug/ExampleApp.swf"/>

The unit tests will run in your default application associated with .swf files. To run in a specific version of the standalone Adobe Flash Player projector, you may specify the path to the executable using the command attribute.

On Windows, set the command to an .exe file:

<royaleunit player="flash" swf="bin-debug/ExampleApp.html"
	command="path/to/flashplayer_32_sa_debug.exe"/>

On macOS, set the command to the executable inside an .app package:

<royaleunit player="flash" swf="bin-debug/ExampleApp.html"
	command="/Applications/Flash Player.app/Contents/MacOS/Flash Player Debugger"/>

Useful options

To fail the Ant build if the unit tests fail, set the haltonfailure attribute to true:

<royaleunit player="chromium" swf="${basedir}/bin/js-debug/index.html" haltonfailure="true"/>