Test API

(info) This AI is still in early stages of development.

Test API

A unit test framework for Warzone JS scripts...

 

Overview

The Test API provides a unit testing framework for JS scripts in Warzone 2100. It's inspired by, and loosely based on, the excellent QUnit testing framework.

Step 1

Include the Test API in your script:

include("path/to/Test.js");

Step 2

Define a Test() with a relevant Test Mode and Unit Tests function:

Test("My first test", Test.ANY( ), function() { // assertions go here });

Whenever you define a test, it gets added to a queue. Tests are run sequentially, one after the other with a small delay between each test (so the game doesn't freeze). You can also define asynchronous tests which are useful for testing events.

Step 3

A test is useless unless it tests stuff! Put some Test Assertions in your unit test:

Test("My first test", Test.ANY( ), function() { ok( true, "This assertion will pass" ); equal( false, true, "This assertion will fail" );   });