Metadata tags for defining unit tests with RoyaleUnit
The following ActionScript metadata tags may be used with RoyaleUnit test classes:
Specify a method to run after each test in this class.
[After] public static function after():void { // runs after every test method in the same class }
Specify a static method to run one time, after all tests have completed in this class.
[AfterClass] public static function afterClass():void { // runs after all test methods in the same class have completed }
Using
[AfterClass]
metadata requires a nightly build of Apache Royale 0.9.7. This metadata will not work properly in version 0.9.6.
Specify a method to run before each test in this class.
[Before] public static function before():void { // runs before every test method in the same class }
Specify a static method to run one time, before any tests have run in this class.
[BeforeClass] public static function beforeClass():void { // runs before all test methods in the same class }
Using
[BeforeClass]
metadata requires a nightly build of Apache Royale 0.9.7. This metadata will not work properly in version 0.9.6.
Specify that a specific test method should not run.
[Ignore] [Test] public function ignoredTest():void { // this test will not be run }
Specify the runner to be used with a specific test suite. Should be combined with [Suite]
metadata metadata.
[Suite] [RunWith("org.apache.royale.test.runners.SuiteRunner")] public class MySuite() { }
In most cases, the runner should be org.apache.royale.test.runners.SuiteRunner
, but it is possible to create a custom runner, if desired.
Specify that a class is a test suite. Should be combined with [RunWith]
metadata.
[Suite] [RunWith("org.apache.royale.test.runners.SuiteRunner")] public class MySuite() { public var myTestCase:MyTestCase; public var myOtherSuite:MyOtherSuite; }
To add test classes to the suite, define a public variable for each class, using the class as the variable type. You may also add other suite classes in the same way.
Specify that a method is a test that should be run.
[Test] public function testSimpleAdd():void { var result:Number = 2 + 3; Assert.assertEquals(result, 5); }
To test asynchronous functionality, add the async
modifier to the [Test]
metadata, and use the static methods on the org.apache.royale.test.async.Async
class to set up a context for testing asynchronously.
[Test(async)] public function testAsync():void { Async.delayCall(this, function():void { // add asserts here }, 250); }
In the example above, we use Async.delayCall()
to call a function after 250 milliseconds. See the Async
class for a number of different methods that you can use for asynchronous tests.
The
async
modifier requires a nightly build of Apache Royale 0.9.7. It is not supported in version 0.9.6.
By default, asynchronous tests fail if they do not complete within 500 milliseconds. Set the timeout
modifier on the [Test]
metadata to customize this duration (measured in milliseconds).
[Test(async,timeout="2000")] public function testAsyncWithCustomTimeout():void { }
The
timeout
modifier requires a nightly build of Apache Royale 0.9.7. It is not supported in version 0.9.6.
To require that a specific exception is thrown while a test is running, set the expected
modifier on the [Test]
metadata to the name of the exception class.
[Test(expected="RangeError")] public function testWithExpectedException():void { throw new RangeError("Out of range"); }
If the exception class is in a package, include the full package name.
[Test(expected="com.example.CustomError")]
The
expected
modifier requires a nightly build of Apache Royale 0.9.7. It is not supported in version 0.9.6.