Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Useful

...

reference

...

for

...

the

...

most

...

used

...

Metadata

...

tags

...

in

...

FlexUnit

...

There

...

are

...

a

...

lot

...

of

...

Metadata

...

tags

...

used

...

in

...

FlexUnit,

...

and

...

if

...

you're

...

still

...

new

...

to

...

the

...

framework

...

it

...

can

...

be

...

a

...

bit

...

overwhelming

...

to

...

know

...

what

...

to

...

use

...

and

...

what

...

can

...

be

...

included

...

inside

...

them.

...

Here's

...

a

...

comprehensive

...

list

...

of

...

the

...

commonly

...

used

...

tags

...

with

...

a

...

brief

...

explanation

...

of

...

where

...

they

...

can

...

be

...

used.

...

You

...

should

...

be

...

able

...

to

...

find

...

reference

...

to

...

most

...

of

...

these

...

in

...

the

...

code

...

examples

...

listed

...

in

...

this

...

wiki.

...

BeforeClass

– Used to specify a static method within a TestCase should run one time, before the constructor and all test cases, this only happens once per TestCase, per case execution, regardless of how many tests are in the test case. It's most commonly a BeforeClass marked method would be used to create tables, or connect to a database that would be used in a group of tests. For more information about BeforeClass see Sequences

  • ''Attributes:''

...

  • order,

...

  • description,

...

  • timeout,

...

  • async,

...

  • ui,

...

  • user

...

  • defined

AfterClass

– Used to specify a static method within a TestCase should run once, after all of the tests in a given test case are complete. In other words, when all of the tests in a test case are complete, before proceeding to the next testcase, this method executes. Conversely to a BeforeClass method AfterClass should preform cleanup on created tables, disconnect from databases, etc. For more information about AfterClass see Sequences

  • ''Attributes:''

...

  • order,

...

  • description,

...

  • timeout,

...

  • async,

...

  • ui,

...

  • user

...

  • defined

Before

– Used to specify a method with a TestCase should be run before every [Test] in that class. For more information about Before see Sequences

  • ''Attributes:''

...

  • order,

...

  • description,

...

  • timeout,

...

  • async,

...

  • ui,

...

  • user

...

  • defined

After

– Used to specify a method with a TestCase should be run after every [Test] in that class. For more information about After see Sequences

  • ''Attributes:''

...

  • order,

...

  • description,

...

  • timeout,

...

  • async,

...

  • ui,

...

  • user

...

  • defined

Rule

– Used to define an advanced [Before]/[After]

...

setup

...

using

...

an

...

entire

...

class

...

allowing

...

for

...

increased

...

reusability.

...

For

...

more

...

information

...

see

...

Creating

...

Rules

  • ''Attributes:''

...

  • order

Suite

– specifies that the class tagged is a Test Suite and will contain a list of public variables typed as the Test Cases or additional Test Suites you wish to run. This tag is commonly paired with the [RunWith] tag to know what runner to use on the tests within this class. (Note: The Suite tag by it self actually does nothing, and RunWith specified with the Suite runner is all you need to set to get a class to run as a suite.) For more information about test suites see Test Suite

  • ''Attributes:''

...

  • order,

...

  • description,

...

  • user

...

  • defined

RunWith("fullyQualifiedName")

...

– Used to identify a specific runner that should be used for this class. Common uses include specifying a class to use the Suite runner or Theory runner. The class specified must be linked into the project and must implement the IRunner interface. For more information about runners see Runners and Builders

  • ''Attributes:''

...

  • none,

...

  • other

...

  • than

...

  • the

...

  • fully

...

  • qualified

...

  • class

...

  • name

...

  • of

...

  • the

...

  • runner.

...

Ignore

– Can be used to ignore a specific [Test] or [Theory],

...

the

...

test

...

will

...

still

...

be

...

built,

...

but

...

will

...

be

...

skipped

...

over

...

when

...

running

...

all

...

tests

...

in

...

the

...

TestCase.

...

The

...

test

...

marked

...

with

...

this

...

tag

...

is

...

still

...

counted

...

in

...

the

...

total

...

tests

...

count.

...

For

...

more

...

information

...

about

...

Ignore

...

see

...

[Ignore

...

]

  • ''Attributes:''

...

  • description,

...

  • user

...

  • defined

Test

– Is used to specify that a method in a TestCase is a method you want FlexUnit to test. There are additional attributes that can be added to this tag such as (async) which is needed if the test is using asyncronous events or (expects="flash.errors.IOError")

...

which

...

indicates

...

that

...

you

...

expect

...

the

...

Test

...

to

...

throw

...

an

...

exception

...

of

...

the

...

specified

...

type

...

and

...

it

...

should

...

catch

...

it.

...

For

...

more

...

information

...

see

...

user

...

defined

...

metadata.

  • ''Attributes:''

...

  • expects,

...

  • order,

...

  • description,

...

  • timeout,

...

  • async,

...

  • ui,

...

  • user

...

  • defined,

...

  • dataProvider

DataPoint(s)

...

– Used on a public static variable or public static function to return testing data. These are then used in conjunction with a Theory by running the Theory once for each item in that particular [DataPoint]'s

...

range.

...

If

...

DataPoints

...

is

...

used,

...

then

...

the

...

tag

...

[ArrayElementType]

...

must

...

also

...

be

...

used

...

to

...

define

...

the

...

type

...

of

...

data

...

the

...

array

...

contains.

...

For

...

more

...

information

...

see

...

Theories,

...

Datapoints,

...

and

...

Assumptions

...

  • ''Attributes:''

...

  • description,

...

  • user

...

  • defined,

...

  • loader

Parameters

– Parameters allow for a multitude of values to be passed into a constructor of a TestCase. For more information about Parameterized testing seeParameterized Testing

  • ''Attributes:''

...

  • description,

...

  • user

...

  • defined,

...

  • loader

Theory

– Used to test a full range of expected results with the help of DataPoint objects or functions. The Theory should specify accepted arguments of types matching to your declared DataPoints. FlexUnit will run all the theories for all possible combinations of arguments with the DataPoint objects that match argument types.
More info on Theories see Theories, Datapoints, and Assumptions

  • ''Attributes:''

...

  • description,

...

  • user

...

  • defined

...

Other

...

tags:

ArrayElementType

– Used to define the associated object type contained with an Array, most specifically used with a static variable, or function, marked as a DataPoint. Keep in mind that this piece of metadata is not unique to FlexUnit 4, however is required by [ to function properly.

Meta Data Attributes:

expects

Code Block
actionscript
actionscript


h2. [\[ArrayElementType\]|FlexUnit ArrayElementType]
-- Used to define the associated object type contained with an Array, most specifically used with a static variable, or function, marked as a [DataPoint|FlexUnit Metadata#DataPoint.28s.29].  Keep in mind that this piece of metadata is not unique to FlexUnit 4, however is required by [ to function properly.

h1 Meta Data Attributes: h1

h2. expects

{code:actionscript}
[Test(description="Ensure failure when two items are not strictly equal", expects="flexunit.framework.AssertionFailedError")]
public function testAssertStrictlyEqualsFails():void {
     Assert.assertStrictlyEquals( 5, "5" );
}
{code}

– adding this bit of metadata to your tag indicates to the runner that there is an expectation for an error to be thrown and if the error specified is caught then all is good, otherwise the test is a failure.

h2 order

Code Block
actionscript
actionscript
-- adding this bit of metadata to your tag indicates to the runner that there is an expectation for an error to be thrown and if the error specified is caught then all is good, otherwise the test is a failure.

h2 order

{code:actionscript}
[Before(order=1)]
public function setUp() : void
{
     panel = new Panel();
}

[Before(order=2, async, ui)]
public function otherSetUp() : void
{
     Async.proceedOnEvent(this, panel, FlexEvent.CREATION_COMPLETE);
         
     UIImpersonator.addChild(panel);
}

– adding this bit of metadata to your tag sets the sort order for this test in relation to all the tests within the test case. Keep in mind that if you override sorting by setting your own sort then you will have to identify what metadata you're going to use to calculate sorting. If you're looking for more information on setting up your own sorting see Sorting.

description

Code Block
actionscript
actionscript
{code}

-- adding this bit of metadata to your tag sets the sort order for this test in relation to all the tests within the test case.  Keep in mind that if you override sorting by setting your own sort then you will have to identify what metadata you're going to use to calculate sorting.  If you're looking for more information on setting up your own sorting see *Sorting*.

h2. description

{code:actionscript}
[Test(description="Ensure that the assertNull function correctly works when a value of null is provided")]
public function testAssertNull():void {
    Assert.assertNull( null );
}
{code}

-- This bit of metadata on your tag is used generally to explain the functionality of your test method.

– This bit of metadata on your tag is used generally to explain the functionality of your test method.

<b>Note:</b>

...

Do

...

not

...

include

...

'<',

...

'>',

...

'&',

...

or

...

'%'.

...

signs

...

in

...

your

...

descriptions,

...

since

...

metadata

...

is

...

parsed

...

into

...

xml

...

and

...

will

...

as

...

a

...

result

...

cause

...

an

...

error

...

with

...

your

...

test.

...

Instead

...

you

...

will

...

need

...

to

...

replace

...

them

...

with

...

their

...

markup

...

forms (< > & and % respectively).

timeout

Code Block
actionscript
actionscript
 (&lt; &gt; &amp; and &#37; respectively).

h2. timeout

{code:actionscript}
[Test(async, ui, timeout="1000")]
public function eventWasNotDispatchedWithoutClick() : void 
{
     Async.failOnEvent(this, panel, "userEnteredText");
         
     panel.userText.text = "some text";
}
{code}

-- indicates to the runner that this test 

– indicates to the runner that this test needs to be run within the milliseconds indicated otherwise it is a failure.

async

Code Block
actionscript
actionscript
needs to be run within the milliseconds indicated otherwise it is a failure.

h2. async

{code:actionscript}
[Test(async, ui, timeout="1000")]
public function eventWasNotDispatchedWithoutClick() : void 
{
     Async.failOnEvent(this, panel, "userEnteredText");
         
     panel.userText.text = "some text";
}

– indicates to the runner that this test needs to be monitored for asynchronous activity.

ui

Code Block
actionscript
actionscript
{code}

-- indicates to the runner that this test needs to be monitored for asynchronous activity.

h2. ui

{code:actionscript}
[Before(async, ui)]
public function setUp() : void 
{
     panel = new Panel();
      
     Async.proceedOnEvent(this, panel, FlexEvent.CREATION_COMPLETE);
         
     UIImpersonator.addChild(panel);
}
{code}

-- indicates to the runner that this test needs to instantiate new objects for the test environment.  This attribute is needed if you wish to use the UIImpersonator class in your function.

h2. User Defined Metadata

– indicates to the runner that this test needs to instantiate new objects for the test environment. This attribute is needed if you wish to use the UIImpersonator class in your function.

User Defined Metadata

Code Block
actionscript
actionscript
{code:actionscript}
[Test(ticketNumber=5543242)]

[Theory(author="Bill Smith")]

– this is any other metadata attribute declared within your tag. This can be used to save information about the test, suite, theory, etc. Most often it is used to store author name or bug issue id. Anything can be added as a custom attribute and will simply act as reference with no effect on other attributes or the parent Metadata tag.

loader

– Indicates the loader instance that that is responsible for providing data to the specified variable.

Code Block
actionscript
actionscript
{code}

-- this is any other metadata attribute declared within your tag.  This can be used to save information about the test, suite, theory, etc.  Most often it is used to store author name or bug issue id.  Anything can be added as a custom attribute and will simply act as reference with no effect on other attributes or the parent Metadata tag.

h2. loader

-- Indicates the loader instance that that is responsible for providing data to the specified variable.
{code:actionscript}
public static var dataRetriever1:ParamDataHelper = new ParamDataHelper( "someFakeDataPath.stuff" );
        
[Parameters(loader="dataRetriever1")]
public static var someData:Array;

dataProvider

For parameterized tests, a data Provider is used to pass in a set of data from either an external or user specified source.

Code Block
actionscript
actionscript
{code}

h2. dataProvider

For parameterized tests, a data Provider is used to pass in a set of data from either an external or user specified source.

{code:actionscript}

public static function dataTwo():Array {
    return [ [ 5, 10 ], [ 6, 12 ], [ 7, 14 ] ];
}

[Test(dataProvider="dataTwo")]
public function timesTwoTest( value:int, result:int ):void {
    assertEquals( 2*value, result );
}