You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by wa...@apache.org on 2021/06/14 17:19:12 UTC
[flex-site] 07/11: changes to units for code blocks
This is an automated email from the ASF dual-hosted git repository.
wave pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flex-site.git
commit b74e2a5ff7d645477adaa506b1c8108b654aa43f
Author: Dave Fisher <da...@davefisher.tech>
AuthorDate: Mon Jun 14 08:39:56 2021 -0700
changes to units for code blocks
---
content/flexunit/tutorial/flexunit/Unit-10.md | 383 +++++++++++++++------
content/flexunit/tutorial/flexunit/Unit-11.md | 224 +++++++++----
content/flexunit/tutorial/flexunit/Unit-12.md | 27 +-
content/flexunit/tutorial/flexunit/Unit-13.md | 461 ++++++++++++++++++--------
content/flexunit/tutorial/flexunit/Unit-14.md | 280 +++++++++++-----
content/flexunit/tutorial/flexunit/Unit-15.md | 124 ++++---
content/flexunit/tutorial/flexunit/Unit-16.md | 68 ++--
content/flexunit/tutorial/flexunit/Unit-4.md | 280 +++++++++++-----
content/flexunit/tutorial/flexunit/Unit-5.md | 265 ++++++++++-----
content/flexunit/tutorial/flexunit/Unit-6.md | 153 ++++++---
content/flexunit/tutorial/flexunit/Unit-7.md | 90 +++--
content/flexunit/tutorial/flexunit/Unit-8.md | 258 +++++++++-----
content/flexunit/tutorial/flexunit/Unit-9.md | 42 ++-
13 files changed, 1854 insertions(+), 801 deletions(-)
diff --git a/content/flexunit/tutorial/flexunit/Unit-10.md b/content/flexunit/tutorial/flexunit/Unit-10.md
index f965852..0ba197b 100644
--- a/content/flexunit/tutorial/flexunit/Unit-10.md
+++ b/content/flexunit/tutorial/flexunit/Unit-10.md
@@ -106,16 +106,20 @@ Title: Unit 10 - Mock Classes
<p>Rules are objects that implement a specific interface to allow developer extension of the main test runner provided with FlexUnit 4. Using rules, a developer may create reusable test fixtures, evaluate a test differently or add steps into the test evaluation process. You will examine rules in more detail later; however, they are being briefly introduced at this time as the primary way of using Mockolate is through a Rule.</p>
<p>To use a rule, instantiate a public property in a test case, and decorate the property with the [Rule] metadata:</p>
-<code><pre>[Rule]
-public var myRuleThatDoesSomethingCool:MyRule = new MyRule();</pre></code>
+```
+[Rule]
+public var myRuleThatDoesSomethingCool:MyRule = new MyRule();
+```
<h2>Using the MockolateRule</h2>
<p>Included in the Mockolate library is a rule named MockolateRule. It is specifically for use with FlexUnit 4. The Mockolate rule saves many manual steps required to create mocks.</p>
<p>Different mocking frameworks work in different ways. Mockolate works by creating compiled ActionScript code for the required mock object in memory at runtime. This is an extremely effective and useful technique; however, Flash Player does not allow this operation to occur synchronously. Therefore, setting up a Mockolate mock is an asynchronous process. The Mockolate rule manages these details without your intervention.</p>
<p>To use the rule, include the following:</p>
-<code><pre>[Rule]
-public var mockRule:MockolateRule = new MockolateRule();</pre></code>
+```
+[Rule]
+public var mockRule:MockolateRule = new MockolateRule();
+```
<p>Once the rule is included, you may use a special piece of metadata named [Mock] to create and inject Mockolate mocks. You will do this in the following walkthrough.</p>
@@ -141,24 +145,37 @@ public var mockRule:MockolateRule = new MockolateRule();</pre></code>
</li>
<li>
<p>Take a look at the constructor for the class:</p>
- <code><pre>public function Circle( origin:Point, radius:Number )</pre></code>
- <p>Currently, the constructor takes two arguments, a <code>Point</code> and a <code>Number</code>. In this walkthrough, you will be mocking this object. Mock automatically passes default parameters for all arguments. This means origin will be <code>null</code> and the radius will be <code>0</code>. A circle cannot have a <code>null</code> origin or a radius of <code>0</code>, you will need to handle these cases. Later, you will be shown how to pass actual values to the mock.</p>
+
+```
+public function Circle( origin:Point, radius:Number )
+```
+
+<p>Currently, the constructor takes two arguments, a <code>Point</code> and a <code>Number</code>. In this walkthrough, you will be mocking this object. Mock automatically passes default parameters for all arguments. This means origin will be <code>null</code> and the radius will be <code>0</code>. A circle cannot have a <code>null</code> origin or a radius of <code>0</code>, you will need to handle these cases. Later, you will be shown how to pass actual values to the mock.</p>
</li>
<li>
<p>Comment out the range check for radius.</p>
- <code><pre>
+
+```
// if( ( radius <= 0 || isNaN( radius ) ) {
// throw new RangeError( "Radius must be a positive Number" );
-// }</pre></code>
- <p>You are commenting this out for simplicity. The default radius of 0 will cause the range error to be thrown. This will prevent that from happening.</p>
+// }
+```
+
+<p>You are commenting this out for simplicity. The default radius of 0 will cause the range error to be thrown. This will prevent that from happening.</p>
</li>
<li>
<p>Immediately after the range check for radius, add a null check for origin. If origin is null, instantiate to a new <code>Point</code> with x and y of 0.</p>
- <code><pre>if( origin == null ) {
+
+```
+if( origin == null ) {
origin = new Point( 0, 0 );
-}</pre></code>
- <p>Your <code>Circle</code> constructor should now appear as follows:</p>
- <code><pre>public function Circle( origin:Point, radius:Number ) {
+}
+```
+
+<p>Your <code>Circle</code> constructor should now appear as follows:</p>
+
+```
+public function Circle( origin:Point, radius:Number ) {
// if( ( radius <= 0 || isNaN( radius ) ) {
// throw new RangeError( "Radius must be a positive Number" );
// }
@@ -167,8 +184,10 @@ public var mockRule:MockolateRule = new MockolateRule();</pre></code>
}
this._origin = origin;
this._radius = radius;
-}</pre></code>
- <h3><br />Declare the MockolateRule</h3>
+}
+```
+
+<h3><br />Declare the MockolateRule</h3>
</li>
<li>
<p>Create a new ActionScript class named CircleMockTest in the math.testcases package within the tests directory.</p>
@@ -178,25 +197,36 @@ public var mockRule:MockolateRule = new MockolateRule();</pre></code>
</li>
<li>
<p>Add and instantiate a public variable named <code>mockRule</code> of type <code>MockolateRule</code> to the CircleMockTest class. Mark the variable with <code>[Rule]</code> metadata.</p>
- <code><pre>[Rule]
-public var mockRule:MockolateRule = new MockolateRule();</pre></code>
- <p>If you did not use code-completion, add the import for mockolate.runner.MockolateRule at this time.</p>
+
+```
+[Rule]
+public var mockRule:MockolateRule = new MockolateRule();
+```
+
+<p>If you did not use code-completion, add the import for mockolate.runner.MockolateRule at this time.</p>
</li>
<li>
<p>Add a variable named <code>mockCircle</code> of type <code>Circle</code> to the class. Mark the variable with <code>[Mock]</code> metadata.</p>
- <code><pre>
+
+```
[Mock]
-public var mockCircle:Circle;</pre></code>
- <p><code>[Mock]</code> metadata marks a variable for mock creation and injection. Mock creation is the equivalent of object instantiation within the Mockolate framework. Variables marked with this metadata are prepared for use as Mocks. By using the MockolateRule, this mock will be instantiated with default values prior to any tests being run in the test case.</p>
+public var mockCircle:Circle;
+```
+
+<p><code>[Mock]</code> metadata marks a variable for mock creation and injection. Mock creation is the equivalent of object instantiation within the Mockolate framework. Variables marked with this metadata are prepared for use as Mocks. By using the MockolateRule, this mock will be instantiated with default values prior to any tests being run in the test case.</p>
<p>If you did not use code-completion, add the import for net.digitalprimates.math.Circle at this time.</p>
</li>
<li>
<p>Add a method named <code>shouldBeNotNull()</code>. It will assert that the <code>mockCircle</code> is not null.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldBeNotNull():void {
assertThat(mockCircle, notNullValue() );
-}</pre></code>
- <p>If you did not use code-completion, add the import statements for org.flexunit.assertThat and org.hamcrest.object.notNullValue at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the import statements for org.flexunit.assertThat and org.hamcrest.object.notNullValue at this time.</p>
</li>
<li>
<p>Save CircleMockTest.as.</p>
@@ -204,15 +234,19 @@ public function shouldBeNotNull():void {
</li>
<li>
<p>Open the CircleSuite.as file within the math.testcases package. Add a new public variable named <code>test4</code> with a type of <code>CircleMockTest</code></p>
- <code><pre>[Suite]
+
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class CircleSuite {
public var test1:BasicCircleTest;
public var test2:CircleConstructorTest;
public var test3:CircleTheory;
public var test4:CircleMockTest;
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save the CircleSuite.as file.</p>
</li>
@@ -235,8 +269,10 @@ public class CircleSuite {
<p>By default, Mockolate creates nice, injected mocks.</p>
<p>To create a mock, create the variable as normal and decorate it with the [Mock] metadata.</p>
-<code><pre>[Mock]
-public var myMock:MockableObject;</pre></code>
+```
+[Mock]
+public var myMock:MockableObject;
+```
<p>The [Mock] metadata accepts two possible arguments: <code>type</code> and <code>inject</code></p>
<ul>
@@ -246,8 +282,10 @@ public var myMock:MockableObject;</pre></code>
<p>By default, Mockolate creates a nice, injected mock.</p>
<p>A strict, non-injected mock would appear as:</p>
-<code><pre>[Mock(type="strict",inject="false")]
-public var myMock:MockableObject;</pre></code>
+```
+[Mock(type="strict",inject="false")]
+public var myMock:MockableObject;
+```
<p>Once the mock is created, it can be used in tests. To use the mock you must <i>stub</i> or <i>mock</i> all methods or properties under test.</p>
<ul>
@@ -258,19 +296,35 @@ public var myMock:MockableObject;</pre></code>
<p>A method or property can be stubbed to:</p>
<ul>
<li>Return a getter</li>
- <code><pre>stub(myMock).getter("name").returns("Useful Mock");</pre></code>
+
+```
+stub(myMock).getter("name").returns("Useful Mock");
+```
+
</ul>
<ul>
<li>A method without arguments</li>
- <code><pre>stub(myMock).method("toString").returns("Useful Mock");</pre></code>
+
+```
+stub(myMock).method("toString").returns("Useful Mock");
+```
+
</ul>
<ul>
<li>With args</li>
- <code><pre>stub(myMock).method("add").args(3, 5).returns(8);</pre></code>
+
+```
+stub(myMock).method("add").args(3, 5).returns(8);
+```
+
</ul>
<ul>
<li>With Hamcrest</li>
- <code><pre>stub(myMock).method("repeatIt").args(instanceOf(String)).returns(instanceOf(String));</pre></code>
+
+```
+stub(myMock).method("repeatIt").args(instanceOf(String)).returns(instanceOf(String));
+```
+
</ul>
<p>This list is not exhaustive. If the real object can do it, the mock can likely simulate the behavior. All of these approaches can be used with mocks as well to set required behaviors.</p>
<p>Mocks are used to stand-in as complex objects for a given class or methods under test. Furthermore, they are used to isolate the system under test, so extraneous dependencies are not interfering with test execution or expectations.</p>
@@ -292,14 +346,22 @@ public var myMock:MockableObject;</pre></code>
</li>
<li>
<p>Add a new method <code>shouldBeEqualCircleMock()</code> decorated with the test metadata.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldBeEqualCircleMock():void {
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Set an expectation that the <code>origin</code> getter will be called at least once. To set an expectation, you use the <code>mock()</code> method of the <code>MockolateRule</code>. You will also need to use the <code>getter()</code> method.</p>
- <code><pre>mock( mockCircle ).getter( "origin" ).atLeast( 1 );</pre></code>
- <p>If you did not use code-completion, import mockolate.mock at this time.</p>
+
+```
+mock( mockCircle ).getter( "origin" ).atLeast( 1 );
+```
+
+<p>If you did not use code-completion, import mockolate.mock at this time.</p>
</li>
<li>
<p>Save the CircleMockTest.as file.</p>
@@ -316,14 +378,22 @@ public function shouldBeEqualCircleMock():void {
</li>
<li>
<p>In <code>shouldBeEqualCircleMock()</code>, but after the mock expectation, create a new <code>Circle</code> called <code>circle</code>. As arguments, pass a new origin at <code>Point( 0, 0 )</code> and a radius of <code>0</code>.</p>
- <code><pre>var circle:Circle = new Circle( new Point( 0, 0 ), 0 );</pre></code>
- <p>You are passing this circle because the default mock created an origin at 0, 0 with a radius of 0.</p>
+
+```
+var circle:Circle = new Circle( new Point( 0, 0 ), 0 );
+```
+
+<p>You are passing this circle because the default mock created an origin at 0, 0 with a radius of 0.</p>
<p>If you did not use code-completion, add the import for flash.geom.Point.</p>
</li>
<li>
<p>In <code>shouldBeEqualCircleMock()</code>, after the circle is instantiated, make a call to the <code>equals()</code> method of circle. Pass it the <code>mockCircle</code> as a parameter.</p>
- <code><pre>circle.equals( mockCircle );</pre></code>
- </li>
+
+```
+circle.equals( mockCircle );
+```
+
+</li>
<li>
<p>Save the CircleMockTest.as file.</p>
</li>
@@ -336,8 +406,12 @@ public function shouldBeEqualCircleMock():void {
</li>
<li>
<p>Add the <code>type="strict"</code> annotation to the Mock metadata of <code>mockCircle</code>.</p>
- <code><pre>[Mock( type="strict" )]</pre></code>
- </li>
+
+```
+[Mock( type="strict" )]
+```
+
+</li>
<li>
<p>Save the CircleMockTest.as file.</p>
</li>
@@ -353,8 +427,12 @@ public function shouldBeEqualCircleMock():void {
</li>
<li>
<p>At the top of the <code>shouldBeEqualCircleMock()</code>, add the expectation for <code>radius</code> to be called at least once.</p>
- <code><pre>mock( mockCircle ).getter( "radius" ).atLeast( 1 );</pre></code>
- </li>
+
+```
+mock( mockCircle ).getter( "radius" ).atLeast( 1 );
+```
+
+</li>
<li>
<p>Save the CircleMockTest.as file.</p>
</li>
@@ -374,13 +452,17 @@ public function shouldBeEqualCircleMock():void {
<p>When injected automatically, mocks pass default parameters to any constructor args, 0 for Number, the empty string for Strings, and null for most other objects. In order to set these constructor arguments to anything else you need to inject the mock manually. Mockolate has a special [Mock] annotation called <code>inject</code> that may be applied to modify mock creation. <code>Inject</code> has two values: <code>true</code> or <code>false</code>. A non-injected mock would appear as:</p>
-<code><pre>[Mock( inject="false" )]
-public var mockPoint:Point;</pre></code>
+```
+[Mock( inject="false" )]
+public var mockPoint:Point;
+```
<p>There are two methods to inject a mock, depending on the type, <code>nice()</code> or <code>strict()</code>. The method used must match the mock or an error will be thrown. Both of these take three parameters: the mock, an optional name and optional arguments. Arguments must be specified as an ordered array.</p>
<p>For Point:</p>
-<code><pre>mockPoint = nice( Point, "myPoint", [ 0, 0 ] );</pre></code>
+```
+mockPoint = nice( Point, "myPoint", [ 0, 0 ] );
+```
<h2>Walkthrough 3: Injecting mocks</h2>
@@ -402,48 +484,84 @@ public var mockPoint:Point;</pre></code>
<li>
<p>Modify the current mock <code>Circle</code> to create the mock but not inject. To do so, add the inject annotation to the Mock metadata decorating the <code>mockCircle</code> variable.</p>
<p>Replace:</p>
- <code><pre>[Mock( type="strict" )]
-Public var mockCircle:Circle;</pre></code>
- <p>With</p>
- <code><pre>[Mock( inject="false", type="strict" )
-Public var mockCircle:Circle;</pre></code>
- </li>
+
+```
+[Mock( type="strict" )]
+Public var mockCircle:Circle;
+```
+
+<p>With</p>
+
+```
+[Mock( inject="false", type="strict" )
+Public var mockCircle:Circle;
+```
+
+</li>
<li>
<p>Create a new method named <code>setup()</code> decorated with the Before metadata.</p>
- <code><pre>[Before]
+
+```
+[Before]
public function setup():void {
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>In the before method, inject a strict mock using the <code>strict()</code> method. Pass this method the <code>Circle</code> class, "<code>mockCircle</code>", and the array <code>[ new Point( 0, 0 ), 1 ]</code>. Assign the return for <code>strict()</code> to the <code>mockCircle</code> instance.</p>
- <code><pre>[Before]
+
+```
+[Before]
public function setup():void {
mockCircle = strict( Circle, "mockCircle", [ new Point( 0, 0 ), 1 ] );
-}</pre></code>
- <p>Since the constructor arguments are now being passed, the range test in the <code>Circle</code> constructor is now satisfied. However, the getters will still return default values. Mocks do not use any of the instance properties. You will need to mock the getters for <code>radius</code> and <code>origin</code> to return values.</p>
+}
+```
+
+<p>Since the constructor arguments are now being passed, the range test in the <code>Circle</code> constructor is now satisfied. However, the getters will still return default values. Mocks do not use any of the instance properties. You will need to mock the getters for <code>radius</code> and <code>origin</code> to return values.</p>
<p>If you did not use code-completion, add the import for mockolate.strict.</p>
</li>
<li>
<p>Replace the lines:</p>
- <code><pre>mock( mockCircle ).getter( "origin" ).atLeast( 1 );
-mock( mockCircle ).getter( "radius" ).atLeast( 1 );</pre></code>
- <p>with</p>
- <code><pre>mock( mockCircle ).getter( "origin" ).returns( new Point( 0, 0 ) ).atLeast( 1 );
-mock( mockCircle ).getter( "radius" ).returns( 1 ).atLeast( 1 );</pre></code>
- <p>This will force the getter and setter to return the required values.</p>
+
+```
+mock( mockCircle ).getter( "origin" ).atLeast( 1 );
+mock( mockCircle ).getter( "radius" ).atLeast( 1 );
+```
+
+<p>with</p>
+
+```
+mock( mockCircle ).getter( "origin" ).returns( new Point( 0, 0 ) ).atLeast( 1 );
+mock( mockCircle ).getter( "radius" ).returns( 1 ).atLeast( 1 );
+```
+
+<p>This will force the getter and setter to return the required values.</p>
<p>If you were to run the test now, it would pass with no errors. However, this does not fulfill the test "shouldBeEqualCircleMock"</p>
</li>
<li>
<p>Change the radius of the circle you instantiate, from a value of 0, to a value of 1.</p>
- <code><pre>var circle:Circle = new Circle( new Point( 0, 0 ), 1 );</pre></code>
- <p>We want to compare that this circle is equal to our mock circle, so they should both have the same radius.</p>
+
+```
+var circle:Circle = new Circle( new Point( 0, 0 ), 1 );
+```
+
+<p>We want to compare that this circle is equal to our mock circle, so they should both have the same radius.</p>
</li>
<li>
<p>Replace the line:</p>
- <code><pre>circle.equals( mockCircle );</pre></code>
- <p>With</p>
- <code><pre>assertTrue( circle.equals( mockCircle ) );</pre></code>
- <p>If you did not use code-completion, add the import for org.flexUnit.asserts.assertTrue</p>
+
+```
+circle.equals( mockCircle );
+```
+
+<p>With</p>
+
+```
+assertTrue( circle.equals( mockCircle ) );
+```
+
+<p>If you did not use code-completion, add the import for org.flexUnit.asserts.assertTrue</p>
<h3><br />Revert the changes to the Circle class.</h3>
</li>
<li>
@@ -452,18 +570,25 @@ mock( mockCircle ).getter( "radius" ).returns( 1 ).atLeast( 1 );</pre></code>
</li>
<li>
<p>Uncomment the following section:</p>
- <code><pre>
+
+```
// if ( ( radius <= 0 ) || isNaN( radius ) ) {
// throw new RangeError("Radius must be a positive Number");
-// }</pre></code>
- </li>
+// }
+```
+
+</li>
<li>
<p>Remove the origin null check. This section is no longer required.</p>
<p>Remove:</p>
- <code><pre>if( origin == null ) {
+
+```
+if( origin == null ) {
origin = new Point( 0, 0 );
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save the Circle.as file.</p>
</li>
@@ -496,52 +621,92 @@ mock( mockCircle ).getter( "radius" ).returns( 1 ).atLeast( 1 );</pre></code>
</li>
<li>
<p>Create a private static constant named <code>TOLERANCE</code> as a <code>Number</code>, with a value of <code>.01</code>.</p>
- <code><pre>private static const TOLERANCE:Number = .01;</pre></code>
- </li>
+
+```
+private static const TOLERANCE:Number = .01;
+```
+
+</li>
<li>
<p>Add and instantiate a public variable named <code>mockRule</code> of type <code>MockolateRule</code> to the <code>LayoutTest</code> class. Mark the variable with <code>[Rule]</code> metadata.</p>
- <code><pre>[Rule]
-public var mockRule:MockolateRule = new MockolateRule();</pre></code>
- <p>If you did not use code-completion, add the import for mockolate.runner.MockolateRule at this time.</p>
+
+```
+[Rule]
+public var mockRule:MockolateRule = new MockolateRule();
+```
+
+<p>If you did not use code-completion, add the import for mockolate.runner.MockolateRule at this time.</p>
</li>
<li>
<p>Add a variable named <code>mockPoint</code> of type <code>Point</code> to the class. Mark the variable with <code>[Mock]</code> metadata.</p>
- <code><pre>[Mock]
-public var mockPoint:Point;</pre></code>
- <p>If you did not use code completion, add the import for flash.geom.Point at this time.</p>
+
+```
+[Mock]
+public var mockPoint:Point;
+```
+
+<p>If you did not use code completion, add the import for flash.geom.Point at this time.</p>
<h3><br />Mocking a method</h3>
</li>
<li>
<p>Create a new test method named <code>shouldBeEqualDistance()</code>. Decorate it with <code>[Test]</code> metadata.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldBeEqualDistance():void {
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Create a new <code>Point</code> called <code>testPoint</code> with x and y values of 5 and 5, respectively.</p>
- <code><pre>var testPoint:Point = new Point( 5, 5 );</pre></code>
- </li>
+
+```
+var testPoint:Point = new Point( 5, 5 );
+```
+
+</li>
<li>
<p>Create a new <code>Point</code> called <code>endPoint</code> with x and y values of 10 and 10, respectively.</p>
- <code><pre>var endPoint:Point = new Point( 10, 10 );</pre></code>
- </li>
+
+```
+var endPoint:Point = new Point( 10, 10 );
+```
+
+</li>
<li>
<p>Create one last <code>Point</code> called <code>summedPoints</code>. Do not instantiate it at this time.</p>
- <code><pre>var summedPoints:Point;</pre></code>
- </li>
+
+```
+var summedPoints:Point;
+```
+
+</li>
<li>
<p>Add an expectation for the <code>add()</code> method of <code>mockPoint</code> to take an argument, <code>testPoint</code>, and return a new <code>Point</code> with x and y values of 10 and 10.</p>
- <code><pre>mock( mockPoint ).method( "add" ).args( testPoint ).returns( new Point( 10, 10 ) );</pre></code>
- <p>The mock will now expect the <code>add()</code> method of <code>mockPoint</code> to be called with the <code>testPoint</code> parameter. When it does, it will return a <code>Point</code> with x and y values of 10 and 10.</p>
+
+```
+mock( mockPoint ).method( "add" ).args( testPoint ).returns( new Point( 10, 10 ) );
+```
+
+<p>The mock will now expect the <code>add()</code> method of <code>mockPoint</code> to be called with the <code>testPoint</code> parameter. When it does, it will return a <code>Point</code> with x and y values of 10 and 10.</p>
</li>
<li>
<p>Make a call to <code>mockPoint.add()</code> passing it the parameter <code>testPoint</code> and assigning the return to <code>summedPoints</code>.</p>
- <code><pre>summedPoints = mockPoint.add( testPoint );</pre></code>
- </li>
+
+```
+summedPoints = mockPoint.add( testPoint );
+```
+
+</li>
<li>
<p>Add a call to <code>assertThat()</code> passing it the parameters <code>endPoint</code> and a new <code>CloseToPointMather</code> with parameters <code>summedPoints</code> and <code>TOLERANCE</code>.</p>
- <code><pre>assertThat( endPoint, new CloseToPointMatcher( summedPoints, TOLERANCE ) );</pre></code>
- <p>If you did not use code completion, add the imports for org.flexunit.assertThat and matcher.CloseToPointMatcher at this time.</p>
+
+```
+assertThat( endPoint, new CloseToPointMatcher( summedPoints, TOLERANCE ) );
+```
+
+<p>If you did not use code completion, add the imports for org.flexunit.assertThat and matcher.CloseToPointMatcher at this time.</p>
</li>
<li>
<p>Save the DistanceTest.as file.</p>
@@ -549,7 +714,9 @@ public function shouldBeEqualDistance():void {
</li>
<li>
<p>Open the CircleSuite.as file within the math.testcases package. Add a new public variable named <code>test5</code> with a type of <code>DistanceTest</code></p>
- <code><pre>[Suite]
+
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class CircleSuite {
public var test1:BasicCircleTest;
@@ -557,8 +724,10 @@ public class CircleSuite {
public var test3:CircleTheory;
public var test4:CircleMockTest;
public var test5:DistanceTest;
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save the CircleSuite.as file.</p>
</li>
diff --git a/content/flexunit/tutorial/flexunit/Unit-11.md b/content/flexunit/tutorial/flexunit/Unit-11.md
index 7157935..afee6dc 100644
--- a/content/flexunit/tutorial/flexunit/Unit-11.md
+++ b/content/flexunit/tutorial/flexunit/Unit-11.md
@@ -31,38 +31,45 @@ Title: Unit 11 - Parameterized Tests
<p>Using a theory, you would supply hundreds or thousands of Gregorian dates as data points. For each data point, you might convert the date to the equivalent Buddhist date. You would then convert each Buddhist date back to the Gregorian date and ensure it matched the original.</p>
<p>With the following pseudocode:</p>
-<code><pre>[DataPoints]
+```
+[DataPoints]
[ArrayElementType("Date")]
public static var dates:Array = [ 1/1/2009,
2/2/2010,
3/3/2011,
1/8/1970,
- 11/12/2090 ];</pre></code>
+ 11/12/2090 ];
+```
<p>Tested under this situation</p>
-<code><pre>[Theory]
+```
+[Theory]
public function shouldConvertSuccessfully( date:Date ):void {
var convert:Converter = new Converter();
var bDate:BDate = converter.convertToBuddhistDate( date );
var gDate:Date = converter.convertToGregorianDate( bDate );
assertEquals( date, gDate );
-}</pre></code>
+}
+```
<p>This type of reversibility is the hallmark of a good theory case.</p>
<p>Also, remember that Theories are about using combinations of data. Given the following pseudocode:</p>
-<code><pre>[DataPoints]
+```
+[DataPoints]
[ArrayElementType("String")]
public static var dates:Array = [ "Trevor", "Joe", "Rob", "Steve" ];
[Theory]
public function traceNames( name1:String, name2:String ):void {
trace( name1 + " - " + name2 );
-}</pre></code>
+}
+```
<p>The expected output is:</p>
-<code><pre>Trevor - Trevor
+```
+Trevor - Trevor
Trevor - Joe
Trevor - Rob
Trevor - Steve
@@ -77,7 +84,8 @@ Rob - Steve
Steve - Trevor
Steve - Joe
Steve - Rob
-Steve - Steve</pre></code>
+Steve - Steve
+```
<p>This use of data point combinations starkly contrasts the use case for Parameterized testing that you will learn in the remainder of the lesson.</p>
@@ -86,18 +94,22 @@ Steve - Steve</pre></code>
<p>Parameterized test cases, like Theories, have methods that accept parameters. However, that is where the comparison ends. Parameterized testing gives us a way to create tests that will use a multitude of known parameters and results. The intention of the Parameterized test is to eliminate the need to copy and paste the same test multiple times, simply changing the input values.</p>
<p>Parameterized tests require the Parameterized runner included with FlexUnit 4.1 and later. To use the parameterized test runner, add the RunWith metadata to the class definition.</p>
-<code><pre>[RunWith("org.flexunit.runners.Parameterized")]</pre></code>
+```
+[RunWith("org.flexunit.runners.Parameterized")]
+```
<p>Parameter data is provided as an array. Inside of the array, there is an array for each argument set to be passed for each test case. For example:</p>
-<code><pre>public static var names:Array = [
+```
+public static var names:Array = [
[ "Stevens", "Mary", "Mary Stevens" ],
[ "Doe", "John", "John Doe" ] ];
[Test]
public function nameCombinerTest( lastName:String, firstName:String,
expectedResult:String ):void {
assertEquals( expectedResult, ( firstName + " " + lastName ) );
-}</pre></code>
+}
+```
<p>There are actually two types of Parameterized tests supported by FlexUnit 4.x, which you will learn to use next.</p>
@@ -116,11 +128,13 @@ public function nameCombinerTest( lastName:String, firstName:String,
</ul>
<p>Example</p>
-<code><pre>public static var data:Array = [ [ 0, 0 ], [ 1, 2 ], [ 2, 4 ] ];
+```
+public static var data:Array = [ [ 0, 0 ], [ 1, 2 ], [ 2, 4 ] ];
[Test( dataProvider="data")]
public function doubleTest( value1:int, value2:int ):void {
assertEquals( value1, value2 * 2 );
-}</pre></code>
+}
+```
<h3>JUnit</h3>
@@ -134,7 +148,8 @@ public function doubleTest( value1:int, value2:int ):void {
</ul>
<p>Example</p>
-<code><pre>[Parameters]
+```
+[Parameters]
public static var data:Array = [ [ 0, 0 ], [ 1, 2 ], [ 2, 4 ] ];
[Test]
public function doubleTest():void {
@@ -145,13 +160,15 @@ private var _value2:int;
public function JUnitStyleTest( value1:int, value2:int ) {
_value1 = value1;
_value2 = value2;
-}</pre></code>
+}
+```
<h2>Working with complex objects</h2>
<p>Any type of data can be used in parameterized testing. In fact, some of the most effective testing can occur when you begin using entire objects as the parameters to methods. The following examples are all valid and intended to make you consider how polymorphism and complex types can enhance your testing capabilities.</p>
-<code><pre>public static var data:Array = [ [ new DataGrid(), 50, 70 ],
+```
+public static var data:Array = [ [ new DataGrid(), 50, 70 ],
[ new Label(), 40, 30 ],
[ new Button(), 80, 50 ] ];
[Test(dataProvider="data")]
@@ -166,7 +183,8 @@ public static var data:Array = [ [ new DollarFormatter(), 50, "$50" ],
[Test(dataProvider="data")]
public function positionTest( formatter:IFormatter, value:Number, result:String ):void {
assertEquals( result, formatter.format( value ) );
-}</pre></code>
+}
+```
<h2>Walkthrough 1: Creating a TestNG Style Parameterized Test</h2>
@@ -189,42 +207,65 @@ public function positionTest( formatter:IFormatter, value:Number, result:String
<li>
<p>Mark the GetPointsTest class definition with <code>[RunWith("org.flexunit.runners.Parameterized")]</code> metadata.</p>
-<code><pre>[RunWith("org.flexunit.runners.Parameterized")]
+```
+[RunWith("org.flexunit.runners.Parameterized")]
public class GetPointsTest {
...
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a private static constant named <code>TOLERANCE</code> of data type <code>Number</code> to the class. Set <code>TOLERANCE</code> to <code>.0001</code>.</p>
- <code><pre>private static const TOLERANCE:Number = .0001;</pre></code>
- </li>
+
+```
+private static const TOLERANCE:Number = .0001;
+```
+
+</li>
<li>
<p>Declare a public static array named data within the <code>GetPointsTest</code> class. The array should contain a sub array with point values as shown.</p>
-<code><pre>public static var data:Array = [
+
+```
+public static var data:Array = [
[ new Circle( new Point( 0, 0 ), 5 ), new Point( 5, 0 ), 0 ],
[ new Circle( new Point( 0, 0 ), 5 ), new Point( -5, 0 ), Math.PI ]
-];</pre></code>
+];
+```
+
<p>If you did not use code-completion, add the import for net.digitalprimates.math.Circle and flash.geom.Point at this time.</p>
<p>The data array contains two arrays. Each is passed as a set of parameters, and each represents one run cycle for the tests that take the data. Soon, you will write a method which takes 3 parameters, a circle, a point and a number of radians. That test will run twice, one run using the first array and another using the second.</p>
</li>
<li>
<p>Add a public method named <code>shouldGetPointsOnCircle()</code> to the class. Mark the method with the <code>[Test(dataProvider="data")]</code> metadata.</p>
-<code><pre>[Test(dataProvider="data")]
+
+```
+[Test(dataProvider="data")]
public function shouldGetPointsOnCircle():void {
-}</pre></code>
- <p>Add a <code>circle</code> parameter of type <code>Circle</code>, a point parameter of type <code>Point</code>, and a <code>radians</code> parameter of type <code>Number</code> to the <code>shouldGetPointsOnCircle()</code> method.</p>
+}
+```
+
+<p>Add a <code>circle</code> parameter of type <code>Circle</code>, a point parameter of type <code>Point</code>, and a <code>radians</code> parameter of type <code>Number</code> to the <code>shouldGetPointsOnCircle()</code> method.</p>
<p>The <code>[Test(dataProvider="data")]</code> metadata over the test method will ensure that the data array's values get passed in as the test method's arguments. This is known as TestNG style parameterized testing, because the data is passed into specific test methods via the metadata. TestNG is a testing framework for Java, it pioneered this annotations-based approach.</p>
-<code><pre>[Test(dataProvider="data")]
+
+```
+[Test(dataProvider="data")]
public function shouldGetPointsOnCircle( circle:Circle, point:Point, radians:Number ):void {
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a call to the <code>assertThat()</code> method. Pass <code>circle.getPointOnCircle( radians )</code> and <code>new CloseToPointMatcher( point, TOLERANCE )</code> as its arguments.</p>
-<code><pre>[Test(dataProvider="data")]
+
+```
+[Test(dataProvider="data")]
public function shouldGetPointsOnCircle( circle:Circle, point:Point, radians:Number ):void {
assertThat( circle.getPointOnCircle( radians ), new CloseToPointMatcher( point, TOLERANCE ) );
-}</pre></code>
- <p>If you did not use code-completion, add the imports for org.flexunit.assertThat and matcher.CloseToPointMatcher at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the imports for org.flexunit.assertThat and matcher.CloseToPointMatcher at this time.</p>
<p>The <code>shouldGetPointsOnCircle()</code> method uses the <code>assertThat()</code> statement with the <code>CloseToPointMatcher</code> to create the same kind of test coverage presented in BasicCircleTest class through the <code>shouldGetTopPointOnCircle()</code> and <code>shouldGetBottomPointOnCircle()</code> methods.</p>
</li>
<li>
@@ -237,7 +278,8 @@ public function shouldGetPointsOnCircle( circle:Circle, point:Point, radians:Num
<li>
<p>Add a public variable named <code>test6</code> of type <code>GetPointsTest</code>.</p>
-<code><pre>[Suite]
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class CircleSuite{
public var test1:BasicCircleTest;
@@ -246,8 +288,10 @@ public class CircleSuite{
public var test4:CircleMockTest;
public var test5:DistanceTest;
public var test6:GetPointsTest;
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save CircleSuite.as.</p>
</li>
@@ -278,67 +322,92 @@ public class CircleSuite{
<li>
<p>Add three private variables to the <code>GetPointsTest</code> class. One named <code>circle</code> of type <code>Circle</code>, another named <code>point</code> of type <code>Point</code>, and another named <code>radians</code> of type <code>Number</code>.</p>
-<code><pre>private var circle:Circle;
+```
+private var circle:Circle;
private var point:Point;
-private var radians:Number;</pre></code>
- </li>
+private var radians:Number;
+```
+
+</li>
<li>
<p>Remove the <code>(dataProvider="data")</code> portion of the metadata from the <code>shouldGetPointsOnCircle()</code> test method. Also remove the parameters, as they will be replaced by the instance variables just created.</p>
-<code><pre>[Test(dataProvider="data")]
+```
+[Test(dataProvider="data")]
public function shouldGetPointsOnCircle( circle:Circle, point:Point, radians:Number ):void {
...
-}</pre></code>
- <p>Becomes</p>
-<code><pre>[Test]
+}
+```
+
+<p>Becomes</p>
+
+```
+[Test]
public function shouldGetPointsOnCircle():void {
...
-}</pre></code>
- <h3><br />Add a method to test point distance</h3>
+}
+```
+
+<h3><br />Add a method to test point distance</h3>
</li>
<li>
<p>Add a public function named <code>shouldReturnDistanceEqualToRadius()</code> to the class.</p>
-<code><pre>[Test]
+```
+[Test]
public function shouldReturnDistanceEqualToRadius():void {
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Within the new method, declare a variable named <code>distance</code> of data type <code>Number</code>. Set it equal to <code>Point.distance( circle.getPointOnCircle( radians ), circle.origin )</code>.</p>
-<code><pre>[Test]
+```
+[Test]
public function shouldReturnDistanceEqualToRadius():void {
var distance:Number = Point.distance( circle.getPointOnCircle( radians ), circle.origin );
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a call to the <code>assertThat()</code> method. Pass in <code>distance</code> and <code>equalTo( circle.radius )</code> as its arguments.</p>
-<code><pre>[Test]
+```
+[Test]
public function shouldReturnDistanceEqualToRadius():void {
var distance:Number = Point.distance( circle.getPointOnCircle( radians ), circle.origin );
assertThat( distance, equalTo( circle.radius ) );
-}</pre></code>
- <p>If you did not use code-completion, add the import for org.hamcrest.object.equalTo at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the import for org.hamcrest.object.equalTo at this time.</p>
</li>
<li>
<p>Now you will need to create a class constructor function that assigns the parameters to the variables declared above. It will take in a circle , point, and radians parameters and assign it to the instance variable for each.</p>
-<code><pre>public function GetPointsTest( circle:Circle, point:Point, radians:Number ) {
+```
+public function GetPointsTest( circle:Circle, point:Point, radians:Number ) {
this.circle = circle;
this.point = point;
this.radians = radians;
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Mark the data array with <code>[Parameters]</code> metadata.</p>
-<code><pre>[Parameters]
+```
+[Parameters]
public static var data:Array =
[ [ new Circle( new Point( 0, 0 ), 5 ), new Point( 5, 0 ), 0 ],
- [ new Circle( new Point( 0, 0 ), 5 ), new Point( -5, 0 ), Math.PI ] ];</pre></code>
- <p>In the previous walkthrough, parameters were passed in using the <code>dataProvider="data"</code> metadata. In this case, parameters are marked with <code>[Parameters]</code> metadata, which passes them into the constructor before each test method is run. This is the parameterized testing approach used in JUnit, a popular Java Unit testing framework on which FlexUnit bases much of its syntax.</p>
+ [ new Circle( new Point( 0, 0 ), 5 ), new Point( -5, 0 ), Math.PI ] ];
+```
+
+<p>In the previous walkthrough, parameters were passed in using the <code>dataProvider="data"</code> metadata. In this case, parameters are marked with <code>[Parameters]</code> metadata, which passes them into the constructor before each test method is run. This is the parameterized testing approach used in JUnit, a popular Java Unit testing framework on which FlexUnit bases much of its syntax.</p>
</li>
<li>
<p>Save GetPointsTest.as.</p>
@@ -355,7 +424,9 @@ public static var data:Array =
<p>External data for parameterized testing is similar to external data in theories. All external data sources use a dataloader, which must implement the IExternalDependancyLoader interface.</p>
-<code><pre>public static var dataRetriever:IExternalDependencyLoader = new ParamDataHelper( "myUrl" );</pre></code>
+```
+public static var dataRetriever:IExternalDependencyLoader = new ParamDataHelper( "myUrl" );
+```
<p>Depending on the style, the loading method for data is different:</p>
@@ -366,8 +437,10 @@ public static var data:Array =
<li>Set a DataPoints variable and annotate it with the loader property</li>
</ul>
-<code><pre>[DataPoints(loader="dataRetriever")]
-public static var data:Array;</pre></code>
+```
+[DataPoints(loader="dataRetriever")]
+public static var data:Array;
+```
<h3>JUnit</h3>
@@ -375,8 +448,10 @@ public static var data:Array;</pre></code>
<li>Loader is added as an annotation to the [Parameters]</li>
</ul>
-<code><pre>[Parameters(loader="dataRetriever")]
-public static var data:Array;</pre></code>
+```
+[Parameters(loader="dataRetriever")]
+public static var data:Array;
+```
<p>For more info on loading external data, see Unit 9: External Data.</p>
@@ -398,17 +473,24 @@ public static var data:Array;</pre></code>
</li>
<li>
<p>Add a public static variable named <code>getDataPointsLoader</code> of type <code>GetPointsDataHelper</code> to the <code>GetPointsTest</code> class. Instantiate the <code>GetPointsDataHelper</code> passing it a the argument <code>"xml/circlePoints.xml"</code></p>
- <code><pre>public static var getDataPointsLoader:GetPointsDataHelper =
- new GetPointsDataHelper( "xml/circlePoints.xml" );</pre></code>
- <p>If you did not use code-completion, add the import for helper.GetPointsDataHelper at this time.</p>
+
+```
+public static var getDataPointsLoader:GetPointsDataHelper =
+ new GetPointsDataHelper( "xml/circlePoints.xml" );
+```
+
+<p>If you did not use code-completion, add the import for helper.GetPointsDataHelper at this time.</p>
<p>The GetPointsDataHelper class implements IExternalDependencyLoader and IResponder interfaces. It is able to send and receive a data request in test case preparation. The loader itself references a data provider. In a parameterized test case, a static array uses these test parameters.</p>
</li>
<li>
<p>Remove the static values from the data Array and modify the <code>[Parameters]</code> metadata to include a loader <code>[Parameters(loader="getDataPointsLoader")]</code> metadata. It should read as follows:</p>
-<code><pre>[Parameters(loader="getDataPointsLoader")]
-public static var data:Array</pre></code>
- </li>
+```
+[Parameters(loader="getDataPointsLoader")]
+public static var data:Array
+```
+
+</li>
<li>
<p>Save the GetPointsTest.as file.</p>
</li>
diff --git a/content/flexunit/tutorial/flexunit/Unit-12.md b/content/flexunit/tutorial/flexunit/Unit-12.md
index 41f5472..c209484 100644
--- a/content/flexunit/tutorial/flexunit/Unit-12.md
+++ b/content/flexunit/tutorial/flexunit/Unit-12.md
@@ -68,15 +68,21 @@ Title: Unit 12 - Running Tests from Different Versions
<li>
<p>Open the TestAssert.as file in the fu1 package in the tests folder.</p>
<p>As you examine the class file you will notice a few differences about these test methods. The <code>TestAssert</code> class extends from the <code>TestCase</code> class. The TestCase class was the base class for all tests in FlexUnit .9.</p>
-<code><pre>public class TestAssert extends TestCase {
+
+```
+public class TestAssert extends TestCase {
public function TestAssert( name : String = null ) {
super( name );
}
...
-}</pre></code>
+}
+```
+
<p>The class constructor in FlexUnit .9 can be used to provide a name for this test in certain circumstances. In this test it does nothing more than call its <code>super()</code> method. FlexUnit 4.x tests do not descend from any particular class.</p>
<p>Metadata is not used to distinguish tests and fixture from normal methods. Every method in this case prefixes the word <i>test</i> to its name. Take a look at the <code>testMatch()</code> method:</p>
-<code><pre>public function testMatch() : void {
+
+```
+public function testMatch() : void {
Assert.assertMatch(
/fr.*gt/,
"feeefrbgbgbggt" );
@@ -96,8 +102,10 @@ Title: Unit 12 - Running Tests from Different Versions
return;
}
fail();
-}</pre></code>
- <p>There are separate Assert classes in FlexUnit 4 and FlexUnit .9. Both have static methods for making assertions. When running tests in FlexUnit 4 you can use either of these classes, to help maintain backwards compatibility.</p>
+}
+```
+
+<p>There are separate Assert classes in FlexUnit 4 and FlexUnit .9. Both have static methods for making assertions. When running tests in FlexUnit 4 you can use either of these classes, to help maintain backwards compatibility.</p>
<p>FlexUnit 4.x Assert: <code>org.flexunit.Assert</code></p>
<p>FlexUnit 1 Assert: <code>flexunit.framework.Assert</code></p>
<p>For catching errors, FlexUnit 1 uses <code>try, catch</code> statements. FlexUnit 4.x uses <code>expects=""</code> metadata for the same kind of test.</p>
@@ -109,15 +117,18 @@ Title: Unit 12 - Running Tests from Different Versions
<li>
<p>Within the <code><fx:Script></code> block there is a function named <code>currentRunTestSuite()</code>. Add a line that calls the <code>testsToRun.push()</code> method with the argument <code>TestAssert</code>.</p>
-<code><pre>import fu1.TestAssert;
+```
+import fu1.TestAssert;
import math.testcases.CircleSuite;
public function currentRunTestSuite():Array {
var testsToRun:Array = new Array();
testsToRun.push( CircleSuite );
testsToRun.push( TestAssert );
return testsToRun;
-}</pre></code>
- <p>If you did not use code-completion, add the import statement for fu1.TestAssert at this point.</p>
+}
+```
+
+<p>If you did not use code-completion, add the import statement for fu1.TestAssert at this point.</p>
</li>
<li>
<p>Save and Run the FlexUnit4Training.mxml file.</p>
diff --git a/content/flexunit/tutorial/flexunit/Unit-13.md b/content/flexunit/tutorial/flexunit/Unit-13.md
index a892d97..f0c564d 100644
--- a/content/flexunit/tutorial/flexunit/Unit-13.md
+++ b/content/flexunit/tutorial/flexunit/Unit-13.md
@@ -34,11 +34,15 @@ Title: Unit 13 - Working with Asynchronous Operations
<p>FlexUnit 4 contains extensive support for asynchronous tests. All asynchronous tests are decorated with the annotation <code>async</code> which notifies the runner this test is not complete once the method has reached the closing brace.</p>
-<code><pre>[Test( async )]</pre></code>
+```
+[Test( async )]
+```
<p>Decorating a test with async causes the runner to hold that test in memory. The test runner relies on an async handler to notify when the test is complete. Omitting an async handler will cause the test to hang indefinitely. To prevent the test from hanging, we may also decorate the test with the timeout annotation.</p>
-<code><pre>[Test( async, timeout="1000" )]</pre></code>
+```
+[Test( async, timeout="1000" )]
+```
<p>The Async class in FlexUnit 4 contains numerous static methods for handling async testing.</p>
<ul>
@@ -74,21 +78,30 @@ Title: Unit 13 - Working with Asynchronous Operations
</li>
<li>
<p>Remove the automatically created constructor from the class.</p>
-<code><pre>package async.testcases {
+
+```
+package async.testcases {
public class BasicTimerTest {
}
-}</pre></code>
- <h3><br />Create an async test case</h3>
+}
+```
+
+<h3><br />Create an async test case</h3>
</li>
<li>
<p>Declare a new private property named <code>timer</code> of type <code>Timer</code> within the class.</p>
- <code><pre>private var timer:Timer;</pre></code>
- <p>If you did not use code-completion, add the import for flash.utils.Timer at this time.</p>
+
+```
+private var timer:Timer;
+```
+
+<p>If you did not use code-completion, add the import for flash.utils.Timer at this time.</p>
</li>
<li>
<p>Declare setup and teardown methods for the class, each marked with <code>[Before]</code> and <code>[After]</code> metadata. The setup method will instantiate <code>timer</code> with a delay of <code>100</code> and a repeat count of <code>1</code>. The teardown method will check if <code>timer</code> is running, stop it if necessary, and destroy the instance.</p>
-<code><pre>[Before]
+```
+[Before]
public function setUp():void {
timer = new Timer( 100, 1 );
}
@@ -98,61 +111,87 @@ public function tearDown():void {
timer.stop();
}
timer = null;
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Write a test method named <code>shouldCompleteTimer()</code>. It will add an event listener for the <code>TimerEvent.TIMER_COMPLETE</code> event which will call an <code>AsyncHandler()</code> method. This asynchronous test must be marked with <code>[Test( async )]</code> metadata in order to be run asynchronously.</p>
-<code><pre>[Test( async )]
+
+```
+[Test( async )]
public function shouldCompleteTimer():void {
timer.addEventListener( TimerEvent.TIMER_COMPLETE,
Async.asyncHandler( this, handleWin, 100, timer, handleTimeout ),
false, 0, true );
-}</pre></code>
+}
+```
+
<p><code>asyncHandler()</code> calls a success handler or timeout handler depending on whether the <code>TimerEvent.TIMER_COMPLETE</code> event is dispatched before the <code>timeOut</code> limit.</p>
<p>If you did not use code-completion, add the import statements for org.flexunit.async.Async and flash.events.TimerEvent at this time.</p>
<p>Take a look at the <code>Async.asyncHandler()</code> method used within the <code>addEventListener()</code> method in the <code>testTimerComplete()</code> test.</p>
-<code><pre>Async.asyncHandler( this, handleWin, 100, timer, handleTimeout )</pre></code>
+```
+Async.asyncHandler( this, handleWin, 100, timer, handleTimeout )
+```
<p>The prototype of this method is:</p>
-<code><pre>Async.asyncHandler(testCase:Object, eventHandler:Function, timeout:int, passThroughData:Object=null,
- timeoutHandler:Function=null):Function</pre></code>
+```
+Async.asyncHandler(testCase:Object, eventHandler:Function, timeout:int, passThroughData:Object=null,
+ timeoutHandler:Function=null):Function
+```
<p>This method references two functions: <code>handleWin()</code> and <code>handleTimeout()</code>. The method <code>handleWin()</code> is called if the <code>TimerEvent.TIMER_COMPLETE</code> occurs before the <code>timeout</code>, which is set at 100. <code>handleTimeout()</code> is the function called if the event is not dispatched before the timeout. <code>handleWin()</code> will receive both the <code>event</code> and <code>passThroughData</code> objects as arguments. The method <co [...]
</li>
<li>
<p>Add a call to the <code>timer.start()</code> method on the last line of the <code>shouldCompleteTimer()</code> test method.</p>
-<code><pre>[Test( async )]
+
+```
+[Test( async )]
public function shouldCompleteTimer():void {
timer.addEventListener( TimerEvent.TIMER_COMPLETE,
Async.asyncHandler( this, handleWin, 100, timer, handleTimeout ),
false, 0, true );
timer.start();
-}</pre></code>
- <p>You will need to declare both the <code>handleWin()</code> and <code>handleTimeout()</code> functions. They can be specified as protected because they are only run within the specific test case and not by the runner itself.</p>
+}
+```
+
+<p>You will need to declare both the <code>handleWin()</code> and <code>handleTimeout()</code> functions. They can be specified as protected because they are only run within the specific test case and not by the runner itself.</p>
</li>
<li>
<p>Declare the <code>handleWin()</code> function as protected. It should accept two parameters, one named <code>event</code> of type <code>Event</code>, and the other named <code>passThroughData</code> of type <code>Object</code>.</p>
</li>
<li>
<p>The <code>handleTimeout()</code> method should also be declared as protected and accept a single parameter named <code>passThroughData</code> of type <code>Object</code>.</p>
-<code><pre>protected function handleWin( event:Event, passThroughData:Object ):void {
+
+```
+protected function handleWin( event:Event, passThroughData:Object ):void {
}
protected function handleTimeout( passThroughData:Object ):void {
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a call to the <code>Assert.assertEquals()</code> method in the <code>handleWin()</code> method. It should take <code>( event.target as Timer ).currentCount</code> and <code>passThroughData.repeatCount</code> as its arguments.</p>
-<code><pre>protected function handleWin( event:Event, passThroughData:Object ):void {
+
+```
+protected function handleWin( event:Event, passThroughData:Object ):void {
Assert.assertEquals( ( event.target as Timer ).currentCount, passThroughData.repeatCount );
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a call to the <code>Assert.fail()</code> method in the <code>handleTimeout()</code> method. It should take the string <code>"Pending event timed out"</code> as its argument.</p>
-<code><pre>protected function handleTimeout( passThroughData:Object ):void {
+
+```
+protected function handleTimeout( passThroughData:Object ):void {
Assert.fail("Pending event timed out");
-}</pre></code>
+}
+```
+
<p>If you did not use code-completion, add the import statements for flash.events.Event and org.flexunit.Assert at this time.</p>
</li>
<li>
@@ -167,24 +206,36 @@ protected function handleTimeout( passThroughData:Object ):void {
</li>
<li>
<p>Remove the automatically created constructor from AsyncSuite.as.</p>
-<code><pre>package async.testcases {
+
+```
+package async.testcases {
public class AsyncSuite {
}
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Mark the AsyncSuite class definition with <code>[Suite]</code> and <code>[RunWith("org.flexunit.runners.Suite")]</code> metadata.</p>
-<code><pre>package async.testcases {
+
+```
+package async.testcases {
[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class AsyncSuite {
}
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a public variable named <code>test1</code> of type <code>BasicTimerTest</code>.</p>
- <code><pre>public var test1:BasicTimerTest;</pre></code>
- </li>
+
+```
+public var test1:BasicTimerTest;
+```
+
+</li>
<li>
<p>Save AsyncSuite.as.</p>
<p>Normally, a suite is not created to contain a single test case. In this case, we know ahead of time that the <code>Async</code> class will eventually contain more test files.</p>
@@ -199,25 +250,33 @@ protected function handleTimeout( passThroughData:Object ):void {
</li>
<li>
<p>Remove the automatically created constructor from the new class and mark it with <code>[Suite]</code> and <code>[RunWith("org.flexunit.runners.Suite")]</code> metadata.</p>
-<code><pre>package testcases {
+
+```
+package testcases {
[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class AllSuites {
}
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a public variable named <code>circleSuite</code> of type <code>CircleSuite</code> to the new class.</p>
</li>
<li>
<p>Add another public varibale named <code>asyncSuite</code> of type <code>AsyncSuite</code> to the class.</p>
-<code><pre>[Suite]
+
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class AllSuites {
public var circleSuite:CircleSuite;
public var asyncSuite:AsyncSuite;
-}</pre></code>
- <p>If you did not use code-completion, add the imports for math.testcases.CircleSuite and async.testcases.AsynSuite at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the imports for math.testcases.CircleSuite and async.testcases.AsynSuite at this time.</p>
</li>
<li>
<p>Save AllSuites.as.</p>
@@ -228,10 +287,18 @@ public class AllSuites {
</li>
<li>
<p>Replace <code>CircleSuite</code> with <code>AllSuites</code> in the <code>testsToRun.push()</code> statement.</p>
- <code><pre>testsToRun.push( CircleSuite );</pre></code>
- <p>Becomes:</p>
- <code><pre>testsToRun.push( AllSuites );</pre></code>
- <p>If you did not use code-completion, add the import for the testcases.AllSuites at this time.</p>
+
+```
+testsToRun.push( CircleSuite );
+```
+
+<p>Becomes:</p>
+
+```
+testsToRun.push( AllSuites );
+```
+
+<p>If you did not use code-completion, add the import for the testcases.AllSuites at this time.</p>
</li>
<li>
<p>Remove the import statement for math.testcases.CircleSuite from the FlexUnit4Training.mxml file.</p>
@@ -251,7 +318,9 @@ public class AllSuites {
<h2>Understanding error handling with async</h2>
<p>In Unit 5 you learned how to handle errors using the <code>[Test(expects="ErrorType")]</code> metadata. Asynchronous methods can handle errors in the same way. Errors thrown in the handler are still dealt with in the test method.</p>
-<code><pre>[Test( async, expects="Error" )]
+
+```
+[Test( async, expects="Error" )]
public function testTimerComplete():void {
timer.addEventListener( TimerEvent.TIMER_COMPLETE,
Async.asyncHandler( this, handleWin, 100, timer, handleTimeout ),
@@ -260,11 +329,13 @@ public function testTimerComplete():void {
}
protected function handleWin( event:Event, passThroughData:Object ):void {
throw new Error();
-}</pre></code>
+}
+```
<p>As you can see, the <code>Async.asyncHandler</code> is called upon the <code>TIMER_COMPLETE</code> event, just as in the previous walkthrough. The resulting handler is simplistic, but clearly illustrates how the error is then handled through the test, where the metadata reads <code>[Test( async, expects="Error" )]</code>. There are several situations in which you need the message or the resulting handler to utilize <code>passThroughData</code> or additional custom information within t [...]
-<code><pre>[Test( async )]
+```
+[Test( async )]
public function testTimerComplete():void {
timer.addEventListener( TimerEvent.TIMER_COMPLETE,
Async.asyncHandler( this, handleWin, 100, timer, handleTimeout ),
@@ -280,7 +351,8 @@ protected function handleWin( event:Event, passThroughData:Object ):void {
return;
}
Assert.fail( "Incorrect error thrown" );
-}</pre></code>
+}
+```
<p>The <code>try-catch</code> statement is looking for a <code>typeError</code>, and then it continues to evaluate with an <code>assertThat</code> statement, expecting the equality of the <code>timer</code> and <code>passThroughData</code>. In these cases, the <code>expects</code> annotation will weaken the test. The test will only expect the kind of error specified, and it will not assert equality, such as is shown through the <code>catch</code> above.</p>
@@ -294,8 +366,10 @@ protected function handleWin( event:Event, passThroughData:Object ):void {
<p>When the test dispatches the expected event within the time limit, the <code>eventHandler</code> method is then called. Even though the desired event has been dispatched, the test does not automatically pass.</p>
-<code><pre>Async.asyncHandler(testCase:Object, <b>eventHandler:Function</b>, timeout:int, passThroughData:Object=null,
- timeoutHandler:Function=null)</pre></code>
+```
+Async.asyncHandler(testCase:Object, <b>eventHandler:Function</b>, timeout:int, passThroughData:Object=null,
+ timeoutHandler:Function=null)
+```
<h3>Asynchronous timeout</h3>
@@ -303,8 +377,10 @@ protected function handleWin( event:Event, passThroughData:Object ):void {
<p>When a <code>timeoutHandler</code> is specified, a timeout does not mark a test as a failure. If a timeout indicates failure you need to assert as such in the timeout method.</p>
<p>If a <code>timeoutHandler</code> is not passed in, the test merely completes with a generic timeout failure.</p>
-<code><pre>Async.asyncHandler(testCase:Object, eventHandler:Function, timeout:int, passThroughData:Object=null,
- <b>timeoutHandler:Function=null</b>)</pre></code>
+```
+Async.asyncHandler(testCase:Object, eventHandler:Function, timeout:int, passThroughData:Object=null,
+ <b>timeoutHandler:Function=null</b>)
+```
<h3>Failure events</h3>
@@ -329,75 +405,111 @@ protected function handleWin( event:Event, passThroughData:Object ):void {
</li>
<li>
<p>Mark the <code>PrimeNumberGeneratorTest</code> class with <code>[RunWith("org.flexunit.runners.Parameterized")]</code> metadata.</p>
-<code><pre>[RunWith("org.flexunit.runners.Parameterized")]
+
+```
+[RunWith("org.flexunit.runners.Parameterized")]
public class PrimeNumberGeneratorTest {
public function PrimeNumberGeneratorTest() {
}
-}</pre></code>
- <p>You will be using JUnit style paramterized loading for this test. Because this style requires parameters to be set in the constructor, leave the constructor in place.</p>
+}
+```
+
+<p>You will be using JUnit style paramterized loading for this test. Because this style requires parameters to be set in the constructor, leave the constructor in place.</p>
</li>
<li>
<p>Add a private variable named <code>primeGenerator</code> of type <code>PrimeNumberGenerator</code> to the class.</p>
- <code><pre>private var primeNumberGenerator:PrimeNumberGenerator;</pre></code>
- <p>If you did not use code-completion, add the import for net.digitalprimates.math.PrimeNumberGenerator at this time.</p>
+
+```
+private var primeNumberGenerator:PrimeNumberGenerator;
+```
+
+<p>If you did not use code-completion, add the import for net.digitalprimates.math.PrimeNumberGenerator at this time.</p>
</li>
<li>
<p>Add a private static constant named <code>TIMEOUT</code> of data type <code>int</code> and set it to <code>500</code>.</p>
- <code><pre>private static const TIMEOUT:int = 500;</pre></code>
- </li>
+
+```
+private static const TIMEOUT:int = 500;
+```
+
+</li>
<li>
<p>Add another public static variable named <code>numberLoader</code> of type <code>NumberDataHelper</code>. Instantiate the variable with a URL string: "<code>xml/numberList.xml</code>"</p>
- <code><pre>public static var numberLoader:NumberDataHelper = new NumberDataHelper( "xml/numberList.xml" );</pre></code>
- <p>If you did not use code-completion, add the import for helper.NumberDataHelper at this time.</p>
+
+```
+public static var numberLoader:NumberDataHelper = new NumberDataHelper( "xml/numberList.xml" );
+```
+
+<p>If you did not use code-completion, add the import for helper.NumberDataHelper at this time.</p>
</li>
<li>
<p>Create a new static variable named <code>data</code>. Decorate it with the <code>Parameters</code> metadata and pass it a <code>loader</code> of <code>numberLoader</code></p>
-<code><pre>[Parameters(loader="numberLoader")]
-public static var data:Array;</pre></code>
- </li>
+
+```
+[Parameters(loader="numberLoader")]
+public static var data:Array;
+```
+
+</li>
<li>
<p>Add two private instance variables of type <code>Number</code> named <code>value</code> and <code>length</code>. In typical JUnit style, make the constructor take values for each as arguments, and set the instance variables when the constructor is run.</p>
-<code><pre>private var value:Number;
+
+```
+private var value:Number;
private var length:Number;
public function PrimeNumberGeneratorTest( value:Number, length:Number ) {
this.value = value;
this.length = length;
-}</pre></code>
+}
+```
<p>All instance variables for the class should now be declared.</p>
</li>
<li>
<p>Create a new method named <code>setup()</code> and a method named <code>teardown()</code>. Decorate them with the <code>[Before( async )]</code> and <code>[After( async )]</code> metadata, respectively.</p>
-<code><pre>[Before( async )]
+
+```
+[Before( async )]
public function setup():void {
}
[After( async )]
public function teardown():void {
-}</pre></code>
+}
+```
<p>The <code>async</code> annotation notifies the test runner the <code>setup()</code> and <code>teardown()</code> methods are not complete when the end brace is reached. The <code>PrimeNumberGenerator</code> simulates this event through the use of a timer. You will need to specify a complete condition just as you would for an asynchronous test or the startup will hang indefinitely.</p>
</li>
<li>
<p>Within the <code>setup()</code> method, create a new instance of <code>primeNumberGenerator</code>. On the next line, add a call to the method <code>Async.proceedOnEvent()</code> passing the arguments <code>this</code>, <code>primeNumberGenerator</code> and <code>TIMEOUT</code>.</p>
-<code><pre>[Before( async )]
+
+```
+[Before( async )]
public function setup():void {
primeNumberGenerator = new PrimeNumberGenerator();
Async.proceedOnEvent( this, primeNumberGenerator, PrimeGeneratorEvent.GENERATOR_READY,
TIMEOUT );
-}</pre></code>
- <p><code>Async.proceedOnEvent()</code> causes the test runner to wait for the parameter <code>IEventDispatcher</code> to dispatch an event before proceeding. In this case the event is named: <code>PrimeGeneratorEvent.GENERATOR_READY</code>.</p>
+}
+```
+
+<p><code>Async.proceedOnEvent()</code> causes the test runner to wait for the parameter <code>IEventDispatcher</code> to dispatch an event before proceeding. In this case the event is named: <code>PrimeGeneratorEvent.GENERATOR_READY</code>.</p>
<p>If you did not use code completion, add the imports for org.flexunit.async.Async and net.digitalprimates.event.PrimeGeneratorEvent at this time.</p>
</li>
<li>
<p>In the <code>teardown()</code> method, remove the instance of <code>primeNumberGenerator</code>.</p>
-<code><pre>[After( async )]
+
+```
+[After( async )]
public function tearDown():void {
primeNumberGenerator = null;
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Your completed asynchrounous startup should now appear as:</p>
-<code><pre>[RunWith("org.flexunit.runners.Parameterized")]
+
+```
+[RunWith("org.flexunit.runners.Parameterized")]
public class PrimeNumberGeneratorTest {
private var primeNumberGenerator:PrimeNumberGenerator;
public static const TIMEOUT : int = 500;
@@ -419,40 +531,56 @@ public class PrimeNumberGeneratorTest {
this.value = value;
this.length = length;
}
-}</pre></code>
+}
+```
<h3><br />Create the generator test</h3>
</li>
<li>
<p>Add a new test method named <code>shouldCreatePrimeArray()</code> to the class, mark it with <code>[Test(async)]</code> metadata. This method creates a new async handler to the <code>handleEvent()</code> method, passing in the arguments <code>this</code>, <code>primeNumberGenerator</code>, <code>PrimeNumberGenerator.GENERATION_COMPLETE</code>, <code>handleComplete</code> and <code>TIMEOUT</code>.</p>
-<code><pre>[Test(async)]
+
+```
+[Test(async)]
public function shouldCreatePrimeArray():void {
Async.handleEvent( this, primeNumberGenerator, PrimeGeneratorEvent.GENERATION_COMPLETE,
handleComplete, TIMEOUT );
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a call to <code>primeNumberGenerator.generatePrimes()</code> method, passing in the instance variable <code>value</code> as its argument.</p>
-<code><pre>[Test(async)]
+
+```
+[Test(async)]
public function shouldCreatePrimeArray():void {
Async.handleEvent( this, primeNumberGenerator, PrimeGeneratorEvent.GENERATION_COMPLETE,
handleComplete, TIMEOUT );
primeNumberGenerator.generatePrimes( value );
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Create the <code>handleComplete()</code> method referenced in the <code>Async.handleEvent()</code> method from the previous step. It needs to accept two parameters, one named <code>event</code> of type <code>PrimeGeneratorEvent</code>, and another named <code>passThroughData</code> of type Object.</p>
-<code><pre>protected function handleComplete( event:PrimeGeneratorEvent, passThroughData:Object ):void {
-}</pre></code>
- <p>The <code>Async.handleEvent()</code> method above declares no <code>timeoutHandler()</code>, so it will just use the default message. This will suffice for this walkthrough, however it can be added as the last argument of the <code>Async.handleEvent()</code> method if necessary.</p>
+```
+protected function handleComplete( event:PrimeGeneratorEvent, passThroughData:Object ):void {
+}
+```
+
+<p>The <code>Async.handleEvent()</code> method above declares no <code>timeoutHandler()</code>, so it will just use the default message. This will suffice for this walkthrough, however it can be added as the last argument of the <code>Async.handleEvent()</code> method if necessary.</p>
</li>
<li>
<p>Add a call to the <code>assertThat()</code> method within the <code>handleComplete</code> method. It should assert that <code>event.primeList.length</code> is equal to <code>length</code>.</p>
-<code><pre>protected function handleComplete( event:PrimeGeneratorEvent, passThroughData:Object ):void {
+
+```
+protected function handleComplete( event:PrimeGeneratorEvent, passThroughData:Object ):void {
assertThat( event.primeList.length, equalTo( length ) );
-}</pre></code>
- <p>If you did not use code-completion, add the imports for org.flexunit.assertThat and org.hamcrest.object.equalTo at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the imports for org.flexunit.assertThat and org.hamcrest.object.equalTo at this time.</p>
</li>
<li>
<p>Save PrimeNumberGeneratorTest.as.</p>
@@ -460,15 +588,19 @@ public function shouldCreatePrimeArray():void {
</li>
<li>
<p>Open AsyncSuite.as in the async.testcases package. Add a public variable named <code>test2</code> of type <code>PrimeNumberGeneratorTest</code>.</p>
-<code><pre>package async.testcases {
+
+```
+package async.testcases {
[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class AsyncSuite {
public var test1:BasicTimerTest;
public var test2:PrimeNumberGeneratorTest;
}
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Run the FlexUnit4Training.mxml file.</p>
<p>If FlexUnit4Training.mxml ran successfully, you should see the following in your browser window:</p>
@@ -495,7 +627,9 @@ public function shouldCreatePrimeArray():void {
<li>The test would have to wait for the system to complete displaying all the pictures.</li>
</ol>
<p>This is a testable use case. The testing concern is whether the component fires the events and system displays all the pictures. You could use a chain of async handlers.</p>
-<code><pre>[Test( async, ui )]
+
+```
+[Test( async, ui )]
public void shouldSubmitForm():void {
//Create a new alarm clock
//Set an alarm time
@@ -507,7 +641,9 @@ public void shouldSubmitForm():void {
//Load and display other pictures
//Proceed on event: "allPicturesDisplayed"
//Verify expected number of pictures displayed
-}</pre></code>
+}
+```
+
<p>As you can see, this can rapidly become very complex as we wait for event after event. Each of these asynchronous operations could require its own async handler leading to a very large test class. This is a simple example, but many UI components, which we will cover in the next unit, can rapidly devolve into a massive integration test. In addition, some components, especially higher level components, require user interaction that cannot be easily simulated through the use of async cha [...]
<p>FlexUnit 4 contains a special tool for handling these types of use cases called sequences.</p>
@@ -525,7 +661,8 @@ public void shouldSubmitForm():void {
<p>Sequences require the test case to use the custom runner named SequenceRunner. Each sequence is created by instantiating a sequence with the current test case, adding a series of tests, adding an optional assert handler and finally running the sequence.</p>
<p>A simple sequence for a timer would appear as follows:</p>
-<code><pre>[Test( async )]
+```
+[Test( async )]
public function shouldCompleteTimerSequence():void {
var timer:Timer = new Timer( TIMEOUT );
var sequence:SequenceRunner = new SequenceRunner( this );
@@ -536,7 +673,8 @@ public function shouldCompleteTimerSequence():void {
sequence.addStep( new SequenceCaller( timer, timer.stop );
sequence.addAssertHandler( handleSequenceComplete, null );
sequence.run();
-}</pre></code>
+}
+```
<p>In this example, the sequence will: start a timer, wait for the timer to cycle three times, stop the timer and make an assertion. The advantage to this setup is if the timer needed to cycle two more times you would just need to add two more sequence waiters.</p>
<p>In the next walkthrough, you will create your own sequence.</p>
@@ -561,74 +699,119 @@ public function shouldCompleteTimerSequence():void {
</li>
<li>
<p>Add a new private static const named <code>TIMEOUT</code> of type <code>Number</code> and set it to the value <code>500</code>.</p>
- <code><pre>private static const TIMEOUT:Number = 500;</pre></code>
- </li>
+
+```
+private static const TIMEOUT:Number = 500;
+```
+
+</li>
<li>
<p>Add a private variable named <code>service</code> of type <code>ServiceStub</code> to the class.</p>
- <code><pre>private var service:ServiceStub;</pre></code>
- <p>If you did not use code-completion, add the import for net.digitalprimates.stub.ServiceStub at this time.</p>
+
+```
+private var service:ServiceStub;
+```
+
+<p>If you did not use code-completion, add the import for net.digitalprimates.stub.ServiceStub at this time.</p>
</li>
<li>
<p>Create the methods <code>setup()</code> and <code>teardown()</code> and decorate them with the <code>[Before]</code> and <code>[After]</code> metadata respectively. Inside the <code>setup()</code> method create a new instance of <code>service</code> variable. In the <code>teardown()</code> method, set it to null so that it may be garbage collected.</p>
-<code><pre>[Before]
+```
+[Before]
public function setup():void {
service = new ServiceStub();
[After]
public function teardown():void {
service = null;
-}</pre></code>
- <h3><br />Prepare the test case</h3>
+}
+```
+
+<h3><br />Prepare the test case</h3>
</li>
<li>
<p>Create a new test called <code>shouldCompleteRequest()</code>. Mark it with <code>[Test(async)]</code> metadata.</p>
-<code><pre>[Test( async )]
+
+```
+[Test( async )]
public function shouldCompleteRequest():void {
-}</pre></code>
- <p>A request is considered complete when a call to the service instance's <code>shouldCompleteRequest()</code> method has created a connection, sent the request and shutdown the connection. To create a test that listens for all of these events you may either create an asynchrounous chain of handlers or use a sequence. For this test, you will be using a sequence.</p>
+}
+```
+
+<p>A request is considered complete when a call to the service instance's <code>shouldCompleteRequest()</code> method has created a connection, sent the request and shutdown the connection. To create a test that listens for all of these events you may either create an asynchrounous chain of handlers or use a sequence. For this test, you will be using a sequence.</p>
</li>
<li>
<p>Inside the body of <code>shouldCompleteRequest()</code>, declare a new variable <code>sequence</code> of the type <code>org.fluint.sequence.SequenceRunner</code>. Make sure you are using the correct <code>SequenceRunner</code> class.</p>
-<code><pre>[Test( async )]
+
+```
+[Test( async )]
public function shouldCompleteRequest():void {
var sequence:SequenceRunner = new SequenceRunner( this );
-}</pre></code>
- <p>If you did not use code-completion, add the import for org.fluint.sequence.SequenceRunner at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the import for org.fluint.sequence.SequenceRunner at this time.</p>
<h3><br />Create the Sequence</h3>
<p>The next block will setup all the <code>SequenceCallers</code> and <code>SequenceWaiters</code> for the <code>SequenceRunner</code>. In this step you will want to test that when <code>sendRefreshRequest()</code> is called service creates a connection to the server, sends a refresh request and closes the connection. It is phrased politely because the server may take longer to complete this request depending on various factors such as connection speed, number of requests, etc.</p>
<p>To add these steps, you will use the sequence's <code>addStep()</code> method. This method has a single parameter, which must be of type <code>org.fluint.sequence.ISequenceStep</code>. A sequence does not execute until its <code>run()</code> method is called.</p>
</li>
<li>
<p>Add a call to <code>sequence.addStep()</code> passing as an argument <code>new SequenceCaller()</code>. Pass the <code>SequenceCaller</code> constructor the arguments <code>service</code> and <code>service.sendRefreshRequest</code>.</p>
- <code><pre>sequence.addStep( new SequenceCaller( service, service.sendRefreshRequest ) );</pre></code>
- <p>If you did not use code-completion, add the import for org.fluint.sequence.SequenceCaller at this time.</p>
+
+```
+sequence.addStep( new SequenceCaller( service, service.sendRefreshRequest ) );
+```
+
+<p>If you did not use code-completion, add the import for org.fluint.sequence.SequenceCaller at this time.</p>
<p><code>SequenceCaller</code> sets up an asynchronous delay for the method call. Instead of calling it now, the method will be called when the sequence runs.</p>
</li>
<li>
<p>Next, add a step to the sequence passing as an argument a new instance of the <code>SequenceWaiter</code> class. Pass it <code>service</code>, <code>StubServiceEvent.CONNECTION_CREATED</code>, and <code>TIMEOUT</code> as its arguments.</p>
- <code><pre>sequence.addStep( new SequenceWaiter( service, StubServiceEvent.CONNECTION_CREATED, TIMEOUT ) );</pre></code>
- <p>If you did not use code-completion, add the imports for org.fluint.sequence.SequenceWaiter and net.digitalprimates.event.StubServiceEvent at this time.</p>
+
+```
+sequence.addStep( new SequenceWaiter( service, StubServiceEvent.CONNECTION_CREATED, TIMEOUT ) );
+```
+
+<p>If you did not use code-completion, add the imports for org.fluint.sequence.SequenceWaiter and net.digitalprimates.event.StubServiceEvent at this time.</p>
<p>A <code>SequenceWaiter</code> creates an asynchronous handler for the parameter event. When this event is dispatched, the sequence will continue. If the event is not dispatched before the timeout, the timeout handler is called. In this case you are using the default timeout handler which will throw an error. When dealing with a long sequence it is generally best practice to create a custom handler for each <code>SequenceWaiter</code> to avoid confusion.</p>
</li>
<li>
<p>On the next line add a call to the <code>addStep()</code> method that instantiates a <code>new SequenceWaiter</code> with arguments <code>service</code>, <code>StubServiceEvent.RECEIVED_REQUEST</code>, and <code>TIMEOUT</code>.</p>
- <code><pre>sequence.addStep( new SequenceWaiter( service, StubServiceEvent.RECEIVED_REQUEST, TIMEOUT ) );</pre></code>
- </li>
+
+```
+sequence.addStep( new SequenceWaiter( service, StubServiceEvent.RECEIVED_REQUEST, TIMEOUT ) );
+```
+
+</li>
<li>
<p>Add a final SequenceWaiter with arguments <code>service</code>, <code>StubServiceEvent.SHUTDOWN_RECEIVED</code>, and <code>TIMEOUT</code>.</p>
- <code><pre>sequence.addStep( new SequenceWaiter( service, StubServiceEvent.SHUTDOWN_RECEIVED, TIMEOUT ) );</pre></code>
- <p>The expected sequence is now set. However, there is no assert set for the completion of the sequence. Currently, as long as all the events are received in order the test is a success. If any of the events are not received within the specified timeout limit, the test fails.</p>
+
+```
+sequence.addStep( new SequenceWaiter( service, StubServiceEvent.SHUTDOWN_RECEIVED, TIMEOUT ) );
+```
+
+<p>The expected sequence is now set. However, there is no assert set for the completion of the sequence. Currently, as long as all the events are received in order the test is a success. If any of the events are not received within the specified timeout limit, the test fails.</p>
</li>
<li>
<p>Add a call to <code>service.addAssertHandler()</code> passing <code>handleCompleteRequest</code> and <code>null</code>.</p>
- <code><pre>sequence.addAssertHandler( handleCompleteRequest, null );</pre></code>
- <p>The <code>addAssertHandler</code> adds an async handler for when the sequence completes successfully and will call the method specified. In this case, it will call <code>handleCompleteRequest()</code>.</p>
+
+```
+sequence.addAssertHandler( handleCompleteRequest, null );
+```
+
+<p>The <code>addAssertHandler</code> adds an async handler for when the sequence completes successfully and will call the method specified. In this case, it will call <code>handleCompleteRequest()</code>.</p>
</li>
<li>
<p>To complete the sequence, call <code>sequence.run()</code> within the <code>shouldCompleteRequest()</code> method.</p>
- <code><pre>sequence.run();</pre></code>
- <p>Your complete <code>shouldCompleteRequest()</code> method should now appear as follows:</p>
-<code><pre>[Test( async )]
+
+```
+sequence.run();
+```
+
+<p>Your complete <code>shouldCompleteRequest()</code> method should now appear as follows:</p>
+
+```
+[Test( async )]
public function shouldCompleteRequest():void {
var sequence:SequenceRunner = new SequenceRunner( this );
sequence.addStep( new SequenceCaller( service, service.sendRefreshRequest ) );
@@ -640,21 +823,31 @@ public function shouldCompleteRequest():void {
TIMEOUT ) );
sequence.addAssertHandler( handleCompleteRequest, null );
sequence.run();
-}</pre></code>
- <p>If you did not use code-completion, add import statements for, org.fluint.sequence package.SequenceCaller and org.fluint.sequence package .SequenceWaiter at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add import statements for, org.fluint.sequence package.SequenceCaller and org.fluint.sequence package .SequenceWaiter at this time.</p>
</li>
<li>
<p>Create the <code>handleCompleteRequest()</code> function. This function takes two paramters; one named <code>event</code> of type <code>Event</code> and another named <code>passThroughData</code> of type <code>Object</code>.</p>
-<code><pre>protected function handleCompleteRequest( event:Event, passThroughData:Object ):void {
-}</pre></code>
- <p>If you did not use code-completion, add the import for flash.events.Event at this time.</p>
+
+```
+protected function handleCompleteRequest( event:Event, passThroughData:Object ):void {
+}
+```
+
+<p>If you did not use code-completion, add the import for flash.events.Event at this time.</p>
</li>
<li>
<p>Add a call to <code>assertFalse()</code> within the <code>handleCompleteRequest()</code> method, asserting that service connection has been terminated.</p>
-<code><pre>protected function handleCompleteRequest( event:Event, passThroughData:Object ):void {
+
+```
+protected function handleCompleteRequest( event:Event, passThroughData:Object ):void {
assertFalse( service.connected );
-}</pre></code>
- <p>If you did not use code-completion, add the imports for org.flexunit.assertThat at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the imports for org.flexunit.assertThat at this time.</p>
</li>
<li>
<p>Save ServiceSequenceTest.as.</p>
@@ -665,7 +858,9 @@ public function shouldCompleteRequest():void {
</li>
<li>
<p>Add a new public variable named <code>test3</code> of type <code>ServiceSequenceTest</code> to the class.</p>
-<code><pre>package async.testcases {
+
+```
+package async.testcases {
[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class AsyncSuite {
@@ -673,8 +868,10 @@ public function shouldCompleteRequest():void {
public var test2:PrimeNumberGeneratorTest;
public var test3:ServiceSequenceTest;
}
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save the AsyncSuite.as file.</p>
</li>
diff --git a/content/flexunit/tutorial/flexunit/Unit-14.md b/content/flexunit/tutorial/flexunit/Unit-14.md
index 4d661b4..ff3e2ba 100644
--- a/content/flexunit/tutorial/flexunit/Unit-14.md
+++ b/content/flexunit/tutorial/flexunit/Unit-14.md
@@ -37,9 +37,7 @@ Title: Unit 14 - UIComponents
<li>
<p>In the tests directory, create a new package named login.testcases.</p>
<p>Alternatively, if you didn't complete the previous lesson or your code is not functioning properly, you can import the FlexUnit4Training.fxp project from the Unit14/Start folder. Please refer to Unit 2: Walkthrough 1 for instructions on importing a Flash Builder project.</p>
-
<h3><br />Create the LoginStartupTest class</h3>
-
</li>
<li>
<p>In the package <code>login.testcases</code>, create a new ActionScript class file named LoginStartupTest.as.</p>
@@ -47,59 +45,91 @@ Title: Unit 14 - UIComponents
</li>
<li>
<p>Add a private static constant named <code>LONG_TIME</code> of data type <code>int</code>. Set the constant to <code>500</code>.</p>
- <code><pre>private static const LONG_TIME:int = 500;</pre></code>
- </li>
+
+```
+private static const LONG_TIME:int = 500;
+```
+
+</li>
<li>
<p>Just below add a private variable named <code>loginComponent</code> of type <code>LoginComponent</code>.</p>
- <code><pre>private var loginComponent:LoginComponent;</pre></code>
- <p>If you did not use code-completion, add the import for net.digitalprimates.components.login.LoginComponent at this time.</p>
+
+```
+private var loginComponent:LoginComponent;
+```
+
+<p>If you did not use code-completion, add the import for net.digitalprimates.components.login.LoginComponent at this time.</p>
</li>
<li>
<p>Create a new public method named <code>setup()</code> and a new public method named <code>teardown()</code>. Decorate them with <code>[Before(async, ui)]</code> and <code>[After(async, ui)]</code>.</p>
-<code><pre>[Before(async, ui)]
+
+```
+[Before(async, ui)]
public function setup():void {
}
[After(async, ui)]
public function teardown() {
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>In the <code>setup()</code> method, create a new instance of <code>loginComponent</code>. On the line immediately following, add a call to <code>Async.proceedOnEvent()</code> passing it the values <code>this</code>, <code>loginComponent</code>, and <code>FlexEvent.CREATION_COMPLETE</code>.</p>
-<code><pre>[Before(async, ui)]
+
+```
+[Before(async, ui)]
public function setup():void {
loginComponent = new LoginComponent();
Async.proceedOnEvent( this, loginComponent, FlexEvent.CREATION_COMPLETE );
-}</pre></code>
- <p>If you did not use code completion, add the imports for org.flexunit.async.Async.</p>
+}
+```
+
+<p>If you did not use code completion, add the imports for org.flexunit.async.Async.</p>
</li>
<li>
<p>Immediately after the async handler add the loginComponent to the UIImpersonator</p>
- <code><pre>UIImpersonator.addChild( loginComponent )</pre></code>
- <p>If you did not use code completion, add the import for org.fluint.uiImpersonation.UIImpersonator.</p>
+
+```
+UIImpersonator.addChild( loginComponent )
+```
+
+<p>If you did not use code completion, add the import for org.fluint.uiImpersonation.UIImpersonator.</p>
<p>The UIImpersonator acts as a facade for the UI allowing visual components to be created without being added to the display list. You will learn more about the UIImpersonator and UI facades in the next section.</p>
</li>
<li>
<p>In the <code>teardown()</code> method, remove the loginComponent from the UIImpersonator and cleanup the instance of loginComponent.</p>
-<code><pre>[After(async, ui)]
+
+```
+[After(async, ui)]
public function teardown():void {
UIImpersonator.removeChild( loginComponent );
loginComponent = null;
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a public function named <code>shouldReturnEmptyFieldsOnStartup()</code>, mark it with <code>[Test(ui)]</code> metadata.</p>
-<code><pre>[Test(ui)]
+
+```
+[Test(ui)]
public function shouldReturnEmptyFieldsOnStartup():void {
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add two calls to the <code>assertThat()</code> method in the <code>shouldReturnEmptyFieldsOnStartup()</code> function. The first should check that <code>loginComponent.usernameTI.text</code> is empty and the other should check that <code>loginComponent.passwordTI.text</code> is empty.</p>
-<code><pre>[Test(ui)]
+
+```
+[Test(ui)]
public function shouldReturnEmptyFieldsOnStartup():void {
assertThat( loginComponent.usernameTI.text == '' );
assertThat( loginComponent.passwordTI.text == '' );
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save LoginStartupTest.as.</p>
<h3><br />Add LoginStartupTest to the Suite</h3>
@@ -112,21 +142,29 @@ public function shouldReturnEmptyFieldsOnStartup():void {
</li>
<li>
<p>Mark the class with <code>[Suite]</code> and <code>[RunWith("org.flexunit.runners.Suite")]</code> metadata.</p>
- <code><pre>package login {
+
+```
+package login {
[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class LoginSuite {
}
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a public variable named <code>test1</code> of type <code>LoginStartupTest</code> to the class.</p>
- <code><pre>[Suite]
+
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class LoginSuite {
public var test1:LoginStartupTest;
-}</pre></code>
- <p>If you did not use code-completion, add the imports for login.testcases.LoginSequenceTest at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the imports for login.testcases.LoginSequenceTest at this time.</p>
</li>
<li>
<p>Save the LoginSuite.as file.</p>
@@ -139,14 +177,18 @@ public class LoginSuite {
</li>
<li>
<p>Add a public variable named <code>loginSuite</code> of type <code>LoginSuite</code> to the class.</p>
- <code><pre>[Suite]
+
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class AllSuites {
public var circleSuite:CircleSuite;
public var layoutTest:LayoutTest;
public var loginSuite:LoginSuite;
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save the AllSuites.as file.</p>
</li>
@@ -206,14 +248,18 @@ public class AllSuites {
<p>To use asynchronous startup, decorate the <code>Before</code> method with the <code>async</code> annotation. If the startup is due to UI, you will also want to decorate it with <code>ui</code>, as in:</p>
-<code><pre>[Before(async, ui)]
-public function setup():void {}</pre></code>
+```
+[Before(async, ui)]
+public function setup():void {}
+```
<p>The main body of the setup method has to instantiate the component, add the async handler and add it to the facade. The UIImpersonator is a static class that mimics a component on the display list. It contains several static functions that may be used in place of the real functions. To add a UIComponent to the facade, use the UIImpersonator's <code>addChild()</code> method, passing the component as the parameter:</p>
-<code><pre>component = new UIComponent();
+```
+component = new UIComponent();
Async.proceedOnEvent( this, component, "creationComplete", TIMEOUT, timeoutHandler );
-UIImpersonator.addChild( component );</pre></code>
+UIImpersonator.addChild( component );
+```
<p>Once the <i>creationComplete</i> is dispatched, tests will continue. Be sure to remove the component from the UIImpersonator at the end of the test. Otherwise, the component will remain in memory.</p>
@@ -221,13 +267,15 @@ UIImpersonator.addChild( component );</pre></code>
<p>In some cases, such as when using the ParameterizedRunner, async startup may not be possible. In this case, we will have to create an async startup chain at the beginning of the test. In this instance we create the component as we would in the setup of the asynchronous startup; however we do it at the beginning of the test. We then wait for the creationComplete call before proceeding with the test.</p>
-<code><pre>[Test(async, ui)]
+```
+[Test(async, ui)]
public function componentShouldDoSomething():void {
Component = new UIComponent();
Async.proceedOnEvent( this, component, "creationComplete", TIMEOUT, timeoutHandler );
UIImpersonator.addChild( component );
// rest of the test
-}</pre></code>
+}
+```
<p>With this type of test, you will need to clean up the test by removing the component from the UIImpersonator in all async handlers.</p>
@@ -248,81 +296,127 @@ public function componentShouldDoSomething():void {
</li>
<li>
<p>Immediately before the class declaration, add the <code>RunWith</code> metadata for the Parameterized runner.</p>
- <code><pre>[RunWith("org.flexunit.runners.Parameterized")]</pre></code>
- <p>Declare two private variables of type <code>String</code> named <code>username</code> and <code>password</code>. Also, declare a protected variable named <code>loginComponent</code> of type <code>LoginComponent</code>.</p>
-<code><pre>private var username:String;
+
+```
+[RunWith("org.flexunit.runners.Parameterized")]
+```
+
+<p>Declare two private variables of type <code>String</code> named <code>username</code> and <code>password</code>. Also, declare a protected variable named <code>loginComponent</code> of type <code>LoginComponent</code>.</p>
+
+```
+private var username:String;
private var password:String;
-protected var loginComponent:LoginComponent;</pre></code>
- <p>If you did not use code-completion, add the import for net.digitalprimates.components.login at this time.</p>
+protected var loginComponent:LoginComponent;
+```
+
+<p>If you did not use code-completion, add the import for net.digitalprimates.components.login at this time.</p>
</li>
<li>
<p>Add the data loader for the login data points.</p>
-<code><pre>public static var userAndPasswordDataLoader:UserAndPasswordDataHelper =
- new UserAndPasswordDataHelper("xml/usersAndPasswords.xml" );</pre></code>
- <p>If you did not use code-completion, add the import for helper.UserAndPasswordDataHelper at this time.</p>
+
+```
+public static var userAndPasswordDataLoader:UserAndPasswordDataHelper =
+ new UserAndPasswordDataHelper("xml/usersAndPasswords.xml" );
+```
+
+<p>If you did not use code-completion, add the import for helper.UserAndPasswordDataHelper at this time.</p>
<h3><br />Create the login sequence test</h3>
</li>
<li>
<p>Create a new test named <code>shouldLoginWithProvidedCredentials</code> that takes two arguments, a username of type <code>String</code> and a password of type <code>String</code>. Decorate it with the metadata <code>[Test( async, ui, id="userAndPasswordDataLoader" )]</code>.</p>
-<code><pre>[Test(async, ui, id="userAndPasswordDataLoader")]
+
+```
+[Test(async, ui, id="userAndPasswordDataLoader")]
public function shouldLoginWithProvidedCredentials( username:String, password:String ):void {
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a variable named <code>sequence</code> of type <code>SequenceRunner</code> to the <code>shouldLoginWithProvidedCredentials()</code> method. Instantiate it with <code>this</code> as its argument.</p>
-<code><pre>protected function handleComponentReady(event:FlexEvent, passThroughData:Object ):void {
+
+```
+protected function handleComponentReady(event:FlexEvent, passThroughData:Object ):void {
var sequence:SequenceRunner = new SequenceRunner( this );
-}</pre></code>
- <p>If you did not use auto complete, add the import for org.fluint.sequence.SequenceRunner.</p>
+}
+```
+
+<p>If you did not use auto complete, add the import for org.fluint.sequence.SequenceRunner.</p>
</li>
<li>
<p>Create a new Object called <code>passThroughData</code>. Assign it the <code>username</code> and <code>password</code> constructor arguments.</p>
-<code><pre>var passThroughData:Object = new Object();
+
+```
+var passThroughData:Object = new Object();
passThroughData.username = username;
-passThroughData.password = password;</pre></code>
- </li>
+passThroughData.password = password;
+```
+
+</li>
<li>
<p>Add a call to the <code>sequence.addStep()</code> method, pass in <code>new SequenceSetter( loginComponent.usernameTI, {text:username} )</code> as its argument.</p>
- <code><pre>sequence.addStep( new SequenceSetter( loginComponent.usernameTI, {text:username} ) );</pre></code>
- <p>SequenceSetter simulates a call to the setter during sequence execution.</p>
+
+```
+sequence.addStep( new SequenceSetter( loginComponent.usernameTI, {text:username} ) );
+```
+
+<p>SequenceSetter simulates a call to the setter during sequence execution.</p>
<p>If you did not use auto complete, add the import for org.fluint.sequence.SequenceSetter.</p>
</li>
<li>
<p>Add another call to the <code>sequence.addStep()</code> method just below the last; pass in <code>new SequenceWaiter( loginComponent.usernameTI, FlexEvent.VALUE_COMMIT, LONG_TIME )</code> as its argument.</p>
-<code><pre>sequence.addStep( new SequenceSetter( loginComponent.usernameTI, {text:username} ) );
+
+```
+sequence.addStep( new SequenceSetter( loginComponent.usernameTI, {text:username} ) );
sequence.addStep( new SequenceWaiter( loginComponent.usernameTI, FlexEvent.VALUE_COMMIT,
- LONG_TIME ) );</pre></code>
- <p>If you did not use code-completion, add the imports for org.fluint.sequence.SequenceSetter and org.fluint.sequence.SequenceWaiter at this time.</p>
+ LONG_TIME ) );
+ ```
+
+<p>If you did not use code-completion, add the imports for org.fluint.sequence.SequenceSetter and org.fluint.sequence.SequenceWaiter at this time.</p>
</li>
<li>
<p>Add a call to the <code>sequence.addStep()</code> method; pass in <code>new SequenceSetter( loginComponent.passwordTI, {text:password} )</code> as its argument.</p>
</li>
<li>
<p>Add another call to the <code>sequence.addStep()</code> method just below the last; pass in <code>new SequenceWaiter( loginComponent.passwordTI, FlexEvent.VALUE_COMMIT, LONG_TIME )</code> as its argument.</p>
-<code><pre>sequence.addStep( new SequenceSetter( loginComponent.passwordTI, {text:password} ) );
+
+```
+sequence.addStep( new SequenceSetter( loginComponent.passwordTI, {text:password} ) );
sequence.addStep( new SequenceWaiter( loginComponent.passwordTI, FlexEvent.VALUE_COMMIT,
- LONG_TIME ) );</pre></code>
- </li>
+ LONG_TIME ) );
+ ```
+
+</li>
<li>
<p>Add a call to the <code>sequence.addStep()</code> method, pass in <code>new SequenceEventDispatcher( loginComponent.loginBtn, new MouseEvent( MouseEvent.CLICK, true, false ) )</code> as its argument.</p>
</li>
<li>
<p>Add another call to the <code>sequence.addStep()</code> method, pass in <code>new SequenceWaiter( loginComponent, 'loginSuccess', LONG_TIME, handleSuccessTimeout ) )</code> as its argument.</p>
-<code><pre>sequence.addStep( new SequenceEventDispatcher( loginComponent.loginBtn,
+
+```
+sequence.addStep( new SequenceEventDispatcher( loginComponent.loginBtn,
new MouseEvent( MouseEvent.CLICK, true, false ) ) );
sequence.addStep( new SequenceWaiter( loginComponent, 'loginRequested', LONG_TIME,
- handleSuccessTimeout ) );</pre></code>
- <p>If you did not use code-completion, add the imports for org.fluint.sequence.SequenceEventDispatcher and flash.events.MouseEvent at this time.</p>
+ handleSuccessTimeout ) );
+ ```
+
+<p>If you did not use code-completion, add the imports for org.fluint.sequence.SequenceEventDispatcher and flash.events.MouseEvent at this time.</p>
</li>
<li>
<p>Add a call to the <code>sequence.addAssertHandler()</code> method, pass in <code>handleLoginSuccess</code> and <code>passThroughData</code> as its arguments.</p>
</li>
<li>
<p>Add a call to the run() method, which is required for the sequence to run.</p>
- <code><pre>sequence.addAssertHandler( handleLoginRequested, passThroughData );
-sequence.run();</pre></code>
- <p>With this setup, if the login is requested the event will be handled. If the login request is not fired, control will pass to the timeout handler. The completed method should read as:</p>
-<code><pre>[Test(async, ui, dataProver="userData")]
+
+```
+sequence.addAssertHandler( handleLoginRequested, passThroughData );
+sequence.run();
+```
+
+<p>With this setup, if the login is requested the event will be handled. If the login request is not fired, control will pass to the timeout handler. The completed method should read as:</p>
+
+```
+[Test(async, ui, dataProver="userData")]
public function shouldLoginWithProvidedCredentials( username:String, password:String ):void {
var sequence:SequenceRunner = new SequenceRunner( this );
var passThroughData:Object = new Object();
@@ -340,38 +434,56 @@ public function shouldLoginWithProvidedCredentials( username:String, password:St
handleSuccessTimeout ) );
sequence.addAssertHandler( handleLoginRequested, passThroughData );
sequence.run();
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a protected function named <code>handleLoginRequested()</code>. It should take a parameter named <code>event</code> of type <code>Event</code> and a parameter named <code>passThroughData</code> of data type <code>Object</code>.</p>
-<code><pre>protected function handleLoginRequested( event:Event, passThroughData:Object ):void {
-}</pre></code>
- </li>
+
+```
+protected function handleLoginRequested( event:Event, passThroughData:Object ):void {
+}
+```
+
+</li>
<li>
<p>Add a call to the <code>assertThat()</code>. It should assert that the <code>passThroughData.username</code> variable is <code>equalTo( loginComponent.usernameTI.text.)</code>.</p>
</li>
<li>
<p>Add a call to the <code>assertThat()</code>. It should assert that the <code>passThroughData.password</code> instance variable is equalTo( loginComponent.passwordTI.text ).</p>
-<code><pre>protected function handleLoginRequested( event:Event, passThroughData:Object ):void {
+
+```
+protected function handleLoginRequested( event:Event, passThroughData:Object ):void {
assertThat( passThroughData.username, equalTo( loginComponent.usernameTI.text ) );
assertThat( passThroughData.password, equalTo( loginComponent.passwordTI.text ) );
-}</pre></code>
- <p>If you did not use code-completion, add the imports for org.flexunit.assertThat and org.hamcrest.object.equalTo.</p>
+}
+```
+
+<p>If you did not use code-completion, add the imports for org.flexunit.assertThat and org.hamcrest.object.equalTo.</p>
</li>
<li>
<p>Add a protected function named <code>handleSuccessTimeout()</code> in the class. It should take a parameter named <code>passThroughData</code> of type <code>Object</code>.</p>
-<code><pre>protected function handleSuccessTimeout(passThroughData:Object):void{
-}</pre></code>
- </li>
+
+```
+protected function handleSuccessTimeout(passThroughData:Object):void{
+}
+```
+
+</li>
<li>
<p>In the timeout handler, add a call to <code>fail()</code>, passing it the message "Login request was not received as expected".</p>
</li>
<li>
<p>Add another call to the <code>assertThat()</code> method. It should assert that the instance variable <code>password</code> is <code>not( equalTo( LoginComponent.PASSWORD ) )</code>.</p>
-<code><pre>protected function handleSuccessTimeout(passThroughData:Object):void {
+
+```
+protected function handleSuccessTimeout(passThroughData:Object):void {
fail( "Login request was not received as expected" );
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save LoginStartupTest.as.</p>
<p>Run the FlexUnit4Training.mxml file.</p>
diff --git a/content/flexunit/tutorial/flexunit/Unit-15.md b/content/flexunit/tutorial/flexunit/Unit-15.md
index eec2933..3776e6a 100644
--- a/content/flexunit/tutorial/flexunit/Unit-15.md
+++ b/content/flexunit/tutorial/flexunit/Unit-15.md
@@ -26,7 +26,8 @@ Title: Unit 15 - Creating Testable Code
<p>Highly cohesive code creates strong test fixtures and short, simple tests. A class with low cohesion will frequently have us begging the question, "does this belong in the fixture?" If there is a section of code that <i>should</i> be in the fixture but doing so will create unnecessary overhead for some of the tests we are likely looking at a case of low cohesion. Always remember that a class with high cohesion tends to create tests with high cohesion.</p>
<p>Consider the following database example:</p>
-<code><pre>public class ContactDatabaseConnection {
+```
+public class ContactDatabaseConnection {
public function ContactDatabaseConnection () {
}
public function connect():void {
@@ -38,24 +39,28 @@ Title: Unit 15 - Creating Testable Code
public function formatContact( contact:Contact ):FormattedContact {
//code to format contact
}
-}</pre></code>
+}
+```
<p>Try to imagine the fixture for this interface. The test fixture would need to create a new database connection. It would also need to create a new contact for testing.</p>
-<code><pre>private var testContact:Contact;
+```
+private var testContact:Contact;
private var connection:ContactDatabaseConnection;
[Before]
public function setup():void {
connection = new ContactDatabaseConnection();
connection.connect();
testContact = new Contact();
-}</pre></code>
+}
+```
<p>However, the <code>formatContact()</code> method does not need a database connection. In fact, what does formatting a contact have to do with a <code>ContactDatabaseConnection</code>? These methods do not have a unified test fixture. In one section we would be testing the connect and retrieval functions. The other requires a contact be ready made. Clearly, <code>formatContact()</code> does not belong.</p>
<p>If you find yourself needing a unique fixture for each test in a class it is highly likely you are dealing with a class that contains low cohesion or only temporal cohesion at best. In this situation, you might want to return to the code and find a way to split the class to increase the cohesion.</p>
<p>Here is an improved version of the <code>ContactDatabaseConnection</code> class that should be much easier to test and maintain:</p>
-<code><pre>public class ContactDatabaseConnection {
+```
+public class ContactDatabaseConnection {
public function ContactDatabaseConnection () {
}
public function connect():void {
@@ -64,30 +69,35 @@ private var connection:ContactDatabaseConnection;
public function getContact( itemName:String ):IContact {
//code to retrieve contact
}
-}</pre></code>
+}
+```
<p>And moving the <code>formatContact</code> method into the specific <code>Contact</code> implementation:</p>
-<code><pre>public class Contact implements IContact {
+```
+public class Contact implements IContact {
//contact code
public function formatContact():void {
//format code
}
-}</pre></code>
+}
+```
<h2>Why loosely coupled code can be tested less painfully</h2>
<p>By creating loosely coupled code, we create classes that can more easily be tested in isolation. Tightly coupled code creates a dependency on outside resources that frequently do not belong in the class with which they are coupled.</p>
<p>Consider the following:</p>
-<code><pre>public class BoxOfCrayons() {
+```
+public class BoxOfCrayons() {
private var crayons:Array = new Array();
public function addCrayon( color:String ):void {
var crayon = new WaxCrayon();
crayon.color = color;
crayon.wrapper.color = color;
}
-}</pre></code>
+}
+```
<p>Think of the tests you would need to write for the <code>addCrayon()</code> method:</p>
<ul>
@@ -149,7 +159,8 @@ private var connection:ContactDatabaseConnection;
</li>
<li>
<p>Examine the <code>updateDisplayList()</code> method in this class.</p>
-<code><pre>override public function updateDisplayList( contentWidth:Number, contentHeight:Number ):void {
+```
+override public function updateDisplayList( contentWidth:Number, contentHeight:Number ):void {
...
super.updateDisplayList( contentWidth, contentHeight );
var circle:Circle = new Circle( new Point( contentWidth/2, contentHeight/2 ),
@@ -162,31 +173,44 @@ private var connection:ContactDatabaseConnection;
element.setLayoutBoundsPosition( elementLayoutPoint.x-elementWidth,
elementLayoutPoint.y-elementHeight );
}
-}</pre></code>
+}
+```
<p>This method creates a <code>circle</code> object of type <code>Circle</code> with dimensions based on the <code>contentWidth</code> and <code>contentHeight</code> arguments. The elements of the layout are positioned to points on the circle.</p>
<p>Suppose you wanted to test the functionality of this method. It would be impossible to isolate because the method is dependent on the <code>Circle</code> class.</p>
<p>The circle object could be mocked if the <code>CircleLayout</code> class had its own <code>circle</code> property instead.</p>
</li>
<li>
<p>At the top of the class, create a private circle property.</p>
- <code><pre>private var circle:Circle;</pre></code>
- </li>
+
+```
+private var circle:Circle;
+```
+
+</li>
<li>
<p>Generate a public getter and setter for the property. Right-click the property, select Source > Generate Getter/Setter, and click OK.</p>
-<code><pre>public function get circle():Circle {
+
+```
+public function get circle():Circle {
return _circle;
}
public function set circle(value:Circle):void {
_circle = value;
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a call to the <code>invalidateDisplayList()</code> method on the <code>target</code> property within the setter of the <code>circle</code>.</p>
-<code><pre>public function set circle(value:Circle):void {
+
+```
+public function set circle(value:Circle):void {
circle = value;
target.invalidateDisplayList();
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Remove the line that instantiates the <code>circle</code> object within the <code>updateDisplayList()</code> method.</p>
<code>var circle:Circle = new Circle( new Point( contentWidth/2, contentHeight/2 ), getLayoutRadius( contentWidth, contentHeight ) );</code>
@@ -197,13 +221,16 @@ public function set circle(value:Circle):void {
<li>
<p>Perform a null check for the <code>circle</code> within <code>updateDisplayList()</code> method.</p>
-<code><pre>super.updateDisplayList( contentWidth, contentHeight );
+```
+super.updateDisplayList( contentWidth, contentHeight );
if(circle) {
for ( i = 0; i < target.numElements; i++ ) {
...
}
-}</pre></code>
- <p>The <code>CircleLayout</code> class can now be better tested as it is not dependent on another class.</p>
+}
+```
+
+<p>The <code>CircleLayout</code> class can now be better tested as it is not dependent on another class.</p>
</li>
</ol>
@@ -225,20 +252,28 @@ if(circle) {
</li>
<li>
<p>Just below the <code>equals()</code> method, add a new public method named <code>distanceFrom()</code>. It should return a value of data type <code>Number</code>. It should take a parameter named <code>circle</code> of type <code>Circle</code>.</p>
-<code><pre>public function distanceFrom( circle:Circle ):Number {
-}</pre></code>
- </li>
+
+```
+public function distanceFrom( circle:Circle ):Number {
+}
+```
+
+</li>
<li>
<p>The new method should return <code>Point.distance( this.origin, circle.origin )</code>, which calculates the distance between the <code>Circles</code>' origin points.</p>
-<code><pre>public function distanceFrom( circle:Circle ):Number {
+
+```
+public function distanceFrom( circle:Circle ):Number {
return Point.distance( this.origin, circle.origin );
-}</pre></code>
+}
+```
<h3><br />Modify the equals() method</h3>
<p>The <code>equals()</code> method in <code>Circle</code> may appear simple enough, but can be difficult to test. This comparison is based on radius and origin. Although the radius comparison is about as simple as it could be, the point comparison is based on the accessing the <code>origin.x</code> and <code>origin.y</code> and asserting their equality separately. If you were to isolate and mock the circle for testing, you would have to mock the <code>Point</code> object as well.</p>
-<code><pre>public function equals( circle:Circle ):Boolean {
+```
+public function equals( circle:Circle ):Boolean {
var equal:Boolean = false;
if ( ( circle ) && ( this.radius == circle.radius ) && ( this.origin ) &&
( circle.origin ) ) {
@@ -247,24 +282,33 @@ if(circle) {
}
}
return equal;
-}</pre></code>
+}
+```
<p>Creating an isolated object for testing will ultimately reduce these interdependencies. Mocks should be able to work without the required input of additional mocks. Creating code of this kind will add seams, loosen coupling, and improve quality over all.</p>
</li>
<li>
<p>In the <code>equals()</code> method, replace the line of the second if statement, which checks the equality of this and the comparison circle's origin's x and y values, with a line that checks that <code>this.distanceFrom( circle )</code> is equal to <code>0</code>.</p>
-<code><pre>if ( ( this.origin.x == circle.origin.x ) &&
+```
+if ( ( this.origin.x == circle.origin.x ) &&
( this.origin.y == circle.origin.y ) ) {
equal = true;
-}</pre></code>
- <p>Becomes:</p>
-<code><pre>if ( this.distanceFrom( circle ) == 0 ) {
+}
+```
+
+<p>Becomes:</p>
+
+```
+if ( this.distanceFrom( circle ) == 0 ) {
equal = true;
-}</pre></code>
- <p>The <code>Circle</code> class's new <code>equals()</code> method should read as follows:</p>
+}
+```
+
+<p>The <code>Circle</code> class's new <code>equals()</code> method should read as follows:</p>
-<code><pre>public function equals( circle:Circle ):Boolean {
+```
+public function equals( circle:Circle ):Boolean {
var equal:Boolean = false;
if ( ( circle ) && ( this.radius == circle.radius ) &&
( this.origin ) && ( circle.origin ) ) {
@@ -273,8 +317,10 @@ if(circle) {
}
}
return equal;
-}</pre></code>
- <p>At this point, if you were to mock a <code>Circle</code>, you would only need to mock and create expectations for a <code>circle</code> object. A mock for the <code>Point</code> class is not needed here.</p>
+}
+```
+
+<p>At this point, if you were to mock a <code>Circle</code>, you would only need to mock and create expectations for a <code>circle</code> object. A mock for the <code>Point</code> class is not needed here.</p>
</li>
<li>
<p>Save the Circle.as file</p>
diff --git a/content/flexunit/tutorial/flexunit/Unit-16.md b/content/flexunit/tutorial/flexunit/Unit-16.md
index f27f870..713205c 100644
--- a/content/flexunit/tutorial/flexunit/Unit-16.md
+++ b/content/flexunit/tutorial/flexunit/Unit-16.md
@@ -96,30 +96,46 @@ Title: Unit 16 - Allowing Your Tests to Function with Continuous Integration
</li>
<li>
<p>Within the <code><fx:Script></code> block, there is a method named <code>onCreationComplete()</code>. Remove the body of this method, leaving just the empty shell of the method.</p>
-<code><pre>private function onCreationComplete():void {
-}</pre></code>
- </li>
+
+```
+private function onCreationComplete():void {
+}
+```
+
+</li>
<li>
<p>Within the <code><fx:Script></code> block add a new public variable named <code>core</code> of type <code>FlexUnitCore</code>.</p>
- <code><pre>public var core:FlexUnitCore;</pre></code>
- <p>If you did not use code-completion, add the import statement for and org.flexunit.runner.FlexUnitCore at this time.</p>
+
+```
+public var core:FlexUnitCore;
+```
+
+<p>If you did not use code-completion, add the import statement for and org.flexunit.runner.FlexUnitCore at this time.</p>
<p>The <code>core</code> acts as our runner; we will be adding the <code>CIListener</code> to the core listeners.</p>
</li>
<li>
<p>In the <code>onCreationComplete()</code> method instantiate the <code>core</code> variable to a new <code>FlexUnitCore()</code>. Call the <code>core.addListener()</code> method on the next line, passing it an argument of <code>new CIListener()</code>. On the next line call the <code>core.run( currentRunTestSuite() )</code>.</p>
-<code><pre>private function onCreationComplete():void {
+
+```
+private function onCreationComplete():void {
core = new FlexUnitCore();
core.addListener( new CIListener() );
-}</pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>On the following line, call <code>core.run()</code> passing <code>currentRunTestSuite()</code> as its argument.</p>
-<code><pre>private function onCreationComplete():void {
+
+```
+private function onCreationComplete():void {
core = new FlexUnitCore();
core.addListener( new CIListener() );
core.run( currentRunTestSuite() );
-}</pre></code>
- <p>If you did not use code-completion, add the import statement for org.flexunit.listeners.CIListener at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the import statement for org.flexunit.listeners.CIListener at this time.</p>
</li>
<li>
<p>Save this mxml file. Do not run it at this time.</p>
@@ -141,7 +157,9 @@ Title: Unit 16 - Allowing Your Tests to Function with Continuous Integration
<li>Project tag structure</li>
</ul>
-<code><pre><project name=<i>"project_name"</i> basedir=<i>"project_base"</i> default=<i>"default_target"</i> ></pre></code>
+```
+<project name=<i>"project_name"</i> basedir=<i>"project_base"</i> default=<i>"default_target"</i> >
+```
<h3>Property tag</h3>
@@ -151,7 +169,9 @@ Title: Unit 16 - Allowing Your Tests to Function with Continuous Integration
<li>Property tag structure</li>
</ul>
-<code><pre><property name=<i>"property_name"</i> location=<i>"property_location"</i> /></pre></code>
+```
+<property name=<i>"property_name"</i> location=<i>"property_location"</i> />
+```
<h3>Taskdef tag</h3>
@@ -162,7 +182,9 @@ Title: Unit 16 - Allowing Your Tests to Function with Continuous Integration
<li>Task definition tag structure</li>
</ul>
-<code><pre><taskdef resource=<i>"task_location_within_jar"</i> classpath=<i>"task_jar_location"</i> /></pre></code>
+```
+<taskdef resource=<i>"task_location_within_jar"</i> classpath=<i>"task_jar_location"</i> />
+```
<h3>Target tag</h3>
@@ -175,7 +197,9 @@ Title: Unit 16 - Allowing Your Tests to Function with Continuous Integration
<li>Target tag structure</li>
</ul>
-<code><pre><target name=<i>"target_name"</i> depends=<i>"target_dependencies"</i>></pre></code>
+```
+<target name=<i>"target_name"</i> depends=<i>"target_dependencies"</i>>
+```
<h3>Task</h3>
@@ -188,7 +212,9 @@ Title: Unit 16 - Allowing Your Tests to Function with Continuous Integration
<li>Common task tag structure</li>
</ul>
-<code><pre><taskname id=<i>"task_id"</i> attribute1=<i>"..."</i> attribute2=<i>"..."</i> ... /></pre></code>
+```
+<taskname id=<i>"task_id"</i> attribute1=<i>"..."</i> attribute2=<i>"..."</i> ... />
+```
<ul>
<li>For building projects with Hudson we will be using 6 tasks, Flex Ant task, FlexUnit task, JUnit report task, copy task, zip task and delete task</li>
@@ -273,9 +299,13 @@ Title: Unit 16 - Allowing Your Tests to Function with Continuous Integration
</li>
<li>
<p>First, navigate to your Flex SDK. In most cases, your Flex SDK should be located at root/Program Files/Adobe/Adobe Flash Builder 4/sdks.</p>
- <code><pre><property name="FLEX_HOME"
- location="rootpath:/Program Files/Adobe/Adobe Flash Builder 4/sdks/4.1.0/" /></pre></code>
- <p>It is highly recommended you use Flex 4.1 SDK. Keep every directory in this walkthrough relative to the FLEX_HOME directory, this way the build file is guaranteed to reference these correctly.</p>
+
+```
+<property name="FLEX_HOME"
+ location="rootpath:/Program Files/Adobe/Adobe Flash Builder 4/sdks/4.1.0/" />
+ ```
+
+<p>It is highly recommended you use Flex 4.1 SDK. Keep every directory in this walkthrough relative to the FLEX_HOME directory, this way the build file is guaranteed to reference these correctly.</p>
<h3><br />Install Ant and Hudson</h3>
</li>
<li>
diff --git a/content/flexunit/tutorial/flexunit/Unit-4.md b/content/flexunit/tutorial/flexunit/Unit-4.md
index dfff8b0..58eebba 100644
--- a/content/flexunit/tutorial/flexunit/Unit-4.md
+++ b/content/flexunit/tutorial/flexunit/Unit-4.md
@@ -43,14 +43,16 @@ Title: Unit 4 - FlexUnit Basics
<p>We call the point where objects can be separated from each other seams. Continuing with the lamp example, the light bulb socket and wall plug are both seams. Seams allow us to isolate an object and ensure that we are only testing one object at a time.</p>
<p>Let's examine the following piece of code:</p>
-<code><pre>public class TestSeams {
+```
+public class TestSeams {
private var someMathObj:SomeMathClass = new SomeMathClass();
public function findDistance( a:Number, b:Number ):Number {
var difference:Number = ( b - a );
var distance:Number = someMathObj.abs( difference );
return distance;
}
-}</pre></code>
+}
+```
<p>Unfortunately, you cannot test the <code>findDistance()</code> method alone. That method depends upon <code>SomeMathClass</code> and its <code>abs()</code> function. Therefore, it cannot be isolated. Any attempt to test this method results in testing the code in the TestSeams class, an unknown amount in the SomeMathClass, and the integration between the classes.</p>
<p>When creating new code you must keep the need for seams in mind. Not only does it facilitate testable code, it also has the side effect of creating loosely coupled code with a minimum of interwoven dependencies.</p>
@@ -59,11 +61,13 @@ Title: Unit 4 - FlexUnit Basics
<p>Let's take a look at the Circle class and the <code>getPointOnCircle()</code> method.</p>
-<code><pre>public function getPointOnCircle( t:Number ):Point {
+```
+public function getPointOnCircle( t:Number ):Point {
var x:Number = origin.x + ( radius * Math.cos( t ) );
var y:Number = origin.y + ( radius * Math.sin( t ) );
return new Point( x, y );
-}</pre></code>
+}
+```
<p>In this unit of code:</p>
<ul>
@@ -80,12 +84,14 @@ Title: Unit 4 - FlexUnit Basics
<p>As you can see, most units will need more than one test to fully validate the unit's function.</p>
<p>Here is a unit from the CircleLayout class:</p>
-<code><pre>public function getLayoutRadius( contentWidth:Number, contentHeight:Number ):Number {
+```
+public function getLayoutRadius( contentWidth:Number, contentHeight:Number ):Number {
var maxX:Number = (contentWidth/2)*.8;
var maxY:Number = (contentHeight/2)*.8;
var radius:Number = Math.min( maxX, maxY );
return Math.max( radius, 1 );
-}</pre></code>
+}
+```
<p>While not perfect, this unit has a couple testing advantages over the previous method:</p>
<ul>
@@ -102,18 +108,22 @@ Title: Unit 4 - FlexUnit Basics
<p>As you learned in the previous unit, a test case is merely a collection of individual test methods that test related behaviors. Each of the methods of a test case is decorated with [Test] metadata to signal to the FlexUnit framework that a method is a test. The [Test] metadata tag can also accept user defined attributes for descriptive and organizational purposes</p>
-<code><pre>[Test(description="Test is supposed to fail",issueID="0012443")]
+```
+[Test(description="Test is supposed to fail",issueID="0012443")]
-public function thisTestFails():void {}</pre></code>
+public function thisTestFails():void {}
+```
<p>or system-defined attributes that provide further instructions to FlexUnit when it runs the test.</p>
<p>A test fixture comprises all of the state required to evaluate your test methods. For example, in the following test:</p>
-<code><pre>[Test]
+```
+[Test]
public function shouldComputeCorrectDiameter():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
assertEquals( 10, circle.diameter );
-}</pre></code>
+}
+```
<p>The existence of the Circle is necessary for the assertion and can therefore be considered part of your test fixture.</p>
@@ -135,7 +145,8 @@ public function shouldComputeCorrectDiameter():void {
<li>
<p>Add seven new public functions to the class right under the <code>shouldReturnProvidedRadius()</code> function. They should be named <code>shouldComputeCorrectDiameter()</code>, <code>shouldReturnProvidedOrigin()</code>, <code>shouldReturnTrueForEqualCircle()</code>, <code>shouldReturnFalseForUnequalOrigin()</code>, <code>shouldReturnFalseForUnequalRadius()</code>, <code>shouldGetPointsOnCircle()</code>, and <code>shouldThrowRangeError()</code>.</p>
<p>Mark each function with <code>[Test]</code> metadata.</p>
- <code><pre>[Test]
+ ```
+ [Test]
public function shouldComputeCorrectDiameter():void {
}
[Test]
@@ -155,11 +166,14 @@ public function shouldGetPointsOnCircle():void {
}
[Test]
public function shouldThrowRangeError():void {
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Although you have written out seven methods, only the first five are going to be used in this walkthrough. Within <code>shouldComputeCorrectDiameter()</code>, <code>shouldReturnProvidedOrigin()</code>, <code>shouldReturnTrueForEqualCircle()</code>, <code>shouldReturnFalseForUnequalOrigin()</code>, and <code>shouldReturnFalseForUnequalRadius()</code> declare a local variable named <code>circle</code> of type <code>Circle</code>. Instantiate <code>circle</code> with an origin Point at [...]
- <code><pre>[Test]
+ ```
+ [Test]
public function shouldComputeCorrectDiameter():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
}
@@ -178,78 +192,104 @@ public function shouldReturnFalseForUnequalOrigin():void {
[Test]
public function shouldReturnFalseForUnequalRadius():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Just below the circle instantiation in the <code>shouldComputeCorrectDiameter()</code> method, add a line that calls to the <code>assertEquals()</code> method with arguments <code>10</code> and <code>circle.diameter</code>.</p>
- <code><pre>[Test]
+ ```
+ [Test]
public function shouldComputeCorrectDiameter ():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
assertEquals( 10, circle.diameter );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Just below the circle instantiation in the <code>shouldReturnProvidedOrigin()</code> method, add two lines that each call the <code>assertEquals()</code> method. This test requires two assertion statements because it will check the x and y coordinates' equality to 0, each on a different line.</p>
- <code><pre>[Test]
+ ```
+ [Test]
public function shouldReturnProvidedOrigin():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
assertEquals( 0, circle.origin.x );
assertEquals( 0, circle.origin.y );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a new local variable named <code>circle2</code> of type <code>Circle</code> to the <code>shouldReturnTrueForEqualCircle()</code> method. Instantiate <code>circle2</code> with an origin of <code>(0, 0)</code> and radius of <code>5</code>.</p>
- <code><pre>[Test]
+ ```
+ [Test]
public function shouldReturnTrueForEqualCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var circle2:Circle = new Circle( new Point( 0, 0 ), 5 );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a new line to the <code>shouldReturnTrueForEqualCircle()</code> function that calls to the <code>assertTrue()</code> method with the argument <code>circle.equals( circle2 )</code>.</p>
- <code><pre>[Test]
+ ```
+ [Test]
public function shouldReturnTrueForEqualCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var circle2:Circle = new Circle( new Point( 0, 0 ), 5 );
assertTrue( circle.equals( circle2 ) );
-} </pre></code>
- <p>If you did not use code-completion, add the import for org.flexunit.asserts.assertTrue at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the import for org.flexunit.asserts.assertTrue at this time.</p>
</li>
<li>
<p>Add a variable named <code>circle2</code> of type <code>Circle</code> to the <code>shouldReturnFalseForUnequalOrigin()</code> method. Instantiate <code>circle2</code> with an origin of <code>(0, 5)</code> and a radius of <code>5</code>.</p>
- <code><pre>[Test]
+ ```
+ [Test]
public function shouldReturnFalseForUnequalOrigin():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var circle2:Circle = new Circle( new Point( 0, 5 ), 5 );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a call to the <code>assertFalse()</code> method. The statement <code>circle.equals( circle2 )</code> should be passed in as its argument.</p>
- <code><pre>[Test]
+ ```
+ [Test]
public function shouldReturnFalseForUnequalOrigin():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var circle2:Circle = new Circle( new Point( 0, 5 ), 5);
assertFalse( circle.equals( circle2 ) );
-} </pre></code>
- <p>If you did not use code-completion, add the import for org.flexunit.asserts.assertFalse at this point.</p>
+}
+```
+
+<p>If you did not use code-completion, add the import for org.flexunit.asserts.assertFalse at this point.</p>
</li>
<li>
<p>Add a variable named <code>circle2</code> of type <code>Circle</code> to the <code>shouldReturnFalseForUnequalRadius()</code> method. Instantiate <code>circle2</code> with an origin of <code>(0, 0)</code> and a radius of <code>7</code>.</p>
- <code><pre>[Test]
+ ```
+ [Test]
public function shouldReturnFalseForUnequalRadius():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var circle2:Circle = new Circle( new Point( 0, 0 ), 7);
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a call to the <code>assertFalse()</code> method. The expression <code>circle.equals( circle2 )</code> should be passed in as its argument.</p>
- <code><pre>[Test]
+ ```
+ [Test]
public function shouldReturnFalseForUnequalRadius():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var circle2:Circle = new Circle( new Point( 0, 0 ), 7);
assertFalse( circle.equals( circle2 ) );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save the BasicCircleTest.as file.</p>
</li>
@@ -266,13 +306,15 @@ public function shouldReturnFalseForUnequalRadius():void {
<p>In the section above you used assertions to establish several passing tests. Many took the same form as this simple math example:</p>
-<code><pre>[Test]
+```
+[Test]
public function testAddition():void {
var num1:Number = 5;
var num2:Number = 3;
var total:Number = 8;
assertEquals( total, num1 + num2 );
-}</pre></code>
+}
+```
<ul>
<li>5 and 3 are expected to add up to 8.</li>
@@ -296,13 +338,15 @@ public function testAddition():void {
<p>Consider this slightly modified <code>testAddition()</code> method:</p>
-<code><pre>[Test]
+```
+[Test]
public function testAddition():void {
var num1:Number = 5;
var num2:Number = 3;
var total:Number = 1000;
assertEquals( total, num1 + num2 );
-}</pre></code>
+}
+```
<ul>
<li>The test asserts that 5 + 3 == 1000.</li>
@@ -310,26 +354,30 @@ public function testAddition():void {
</ul>
<p>FlexUnit 4.x catches the <code>AssertionError</code> that is thrown when this test fails, and the following result is displayed within the FlexUnit Results window in Flash Builder:</p>
-<code><pre>
+```
"expected: <1000> but was: <8>"
-</pre></code>
+
+```
<p>A test will be registered as a failure after the <i>first</i> instance of a failed assertion. FlexUnit will not continue to evaluate the other assertions in the method. This means that if multiple assertions are written in a single test you will only receive notification of the first failure and the others will be in an unknown state.</p>
-<code><pre>[Test]
+```
+[Test]
public function testAddition():void {
var num1:Number = 5;
var num2:Number = 3;
var total:Number = 1000;
assertEquals( total, num1 + num2 );
assertEquals( num1 + num2, total );
-}</pre></code>
+}
+```
<p>For example, both of these assertions would fail given the opportunity. However, as soon as FlexUnit catches the first failed assertion it stops the test. The second assert will never be called. The error message would read:</p>
-<code><pre>
+```
"expected: <1000> but was: <8>"
-</pre></code>
+
+```
<p>With multiple assertions in a test, a test can fail for one of several reasons. In diagnosis, it is not immediately clear what caused the test to fail.</p>
@@ -350,33 +398,47 @@ public function testAddition():void {
</li>
<li>
<p>In the <code>shouldGetPointsOnCircle()</code> method, create a local variable named <code>circle</code> of type <code>Circle</code>. This Circle should be instantiated with an origin of <code>(0, 0)</code> and a radius of <code>5</code>.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetPointsOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Declare a variable named <code>point</code> of type <code>Point</code>.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetPointsOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Set the point variable equal to the return value of <code>circle.getPointOnCircle( 0 )</code>. Above that line, it is useful to add a comment line specifying that this is the top-most point of circle.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetPointsOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
//top-most point of circle
point = circle.getPointOnCircle( 0 );
-} </pre></code>
- <p>The <code>getPointOnCircle( t:Number )</code> returns a Circle object's point that corresponds to the radians passed in as the <code>t</code> parameter.</p>
+}
+```
+
+<p>The <code>getPointOnCircle( t:Number )</code> returns a Circle object's point that corresponds to the radians passed in as the <code>t</code> parameter.</p>
</li>
<li>
<p>Add two new lines, each with a call to the <code>assertEquals()</code> method. The first takes the arguments <code>5</code> and <code>point.x</code>. The second takes the arguments <code>0</code> and <code>point.y</code>.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetPointsOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
@@ -384,8 +446,10 @@ public function shouldGetPointsOnCircle():void {
point = circle.getPointOnCircle( 0 );
assertEquals( 5, point.x );
assertEquals( 0, point.y );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Copy these four new lines of code and paste them into the bottom of the function.</p>
<p>Alter the comment in this section to read <code>//bottom-most point on circle</code>.</p>
@@ -396,7 +460,9 @@ public function shouldGetPointsOnCircle():void {
<li>
<p>Update the <code>assertEquals()</code> statements to <code>assertEquals( -5, point.x )</code> and <code>assertEquals( 0, point.y )</code>.</p>
<p>This should create a duplicate set of assertions for the bottom-most point on the circle.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetPointsOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
@@ -408,8 +474,10 @@ public function shouldGetPointsOnCircle():void {
point = circle.getPointOnCircle( Math.PI );
assertEquals( -5, point.x );
assertEquals( 0, point.y );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save BasicCircleTest.as.</p>
</li>
@@ -449,20 +517,26 @@ public function shouldGetPointsOnCircle():void {
</li>
<li>
<p>Replace the <code>shouldGetPointsOnCircle()</code> function with two new public functions in the <code>BasicCircleTest</code> class. These functions will be named so that each clearly represents the point on the circle being tested.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetTopPointOnCircle():void {
}
[Test]
public function shouldGetBottomPointOnCircle():void {
-} </pre></code>
- <p>Although the original <code>shouldGetPointsOnCircle()</code> method contained tests for only the top and bottom points of the Circle, in this Walkthrough you will add tests for the left and right points as well.</p>
+}
+```
+
+<p>Although the original <code>shouldGetPointsOnCircle()</code> method contained tests for only the top and bottom points of the Circle, in this Walkthrough you will add tests for the left and right points as well.</p>
</li>
<li>
<p>Add two new methods named <code>shouldGetRightPointOnCircle()</code> and <code>shouldGetLeftPointOnCircle()</code>.</p>
</li>
<li>
<p>Copy the instantiation of the circle, and declaration of the point from the <code>shouldgetPointsOnCircle()</code> method into each of the four new methods.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetTopPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
@@ -481,11 +555,15 @@ public function shouldGetRightPointOnCircle():void {
public function shouldGetLeftPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Copy the block of code following <code>//top-most point of circle</code> comment into the <code>shouldGetTopPointOnCircle()</code> method. Copy the block following the <code>//bottom-most point of circle</code> comment into the <code>shouldGetBottomPointOnCircle()</code> method.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetTopPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
@@ -502,12 +580,16 @@ public function shouldGetBottomPointOnCircle():void {
point = circle.getPointOnCircle( Math.PI );
assertEquals( -5, point.x );
assertEquals( 0, point.y );
-} </pre></code>
- <p>Because the methods each test specific points, the name is clear enough to distinguish one test from another. Remove the comment fields in each of the tests accordingly.</p>
+}
+```
+
+<p>Because the methods each test specific points, the name is clear enough to distinguish one test from another. Remove the comment fields in each of the tests accordingly.</p>
</li>
<li>
<p>Modify the <code>shouldGetTopPointOnCircle()</code> and <code>shouldGetBottomPointOnCircle()</code> methods to save space by instantiating the point variable as it is declared in each function, much like the circle variable. The comments can be removed as well.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetTopPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( 0 );
@@ -521,45 +603,63 @@ public function shouldGetBottomPointOnCircle():void {
var point:Point = circle.getPointOnCircle( Math.PI );
assertEquals( -5, point.x );
assertEquals( 0, point.y );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>In the <code>shouldGetRightPointOnCircle()</code> method, set the <code>point</code> variable to <code>circle.getPointOnCircle( Math.PI/2 )</code>.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetRightPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( Math.PI/2 );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>In the <code>shouldGetLeftPointOnCircle()</code> method, set the <code>point</code> variable to <code>circle.getPointOnCircle( (3*Math.PI)/2 )</code>.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetLeftPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( (3*Math.PI)/2 );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add two calls to the <code>assertEquals()</code> method to <code>shouldGetRightPointOnCircle()</code>. One should assert that <code>point.x</code> is equal to <code>5</code>, and <code>point.y</code> is equal to <code>0</code>.</p>
-
- <code><pre>[Test]
+
+
+```
+[Test]
public function shouldGetRightPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( Math.PI/2 );
assertEquals( 0, point.x );
assertEquals( 5, point.y );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add two calls to the <code>assertEquals()</code> method to <code>shouldGetLeftPointOnCircle()</code>. One should assert that <code>point.x</code> is equal to <code>0</code>, and <code>point.y</code> is equal to <code>-5</code>.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetLeftPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( (3*Math.PI)/2 );
assertEquals( 0, point.x );
assertEquals( -5, point.y );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Delete the previously used <code>shouldGetPointsOnCircle()</code> method, because its tests have been replicated.</p>
</li>
diff --git a/content/flexunit/tutorial/flexunit/Unit-5.md b/content/flexunit/tutorial/flexunit/Unit-5.md
index fdd2625..9f81d6e 100644
--- a/content/flexunit/tutorial/flexunit/Unit-5.md
+++ b/content/flexunit/tutorial/flexunit/Unit-5.md
@@ -42,7 +42,8 @@ Title: Unit 5 - Developing Static Tests
</ul>
<p>You probably notice several things that need to be tested right away. Minimally, you need to test that the box has 12 crayons. You would need to test that each crayon is of type wax, has a color and a wrapper. You would need to test that the wrapper has a color name and that the color name is the same as the color of the crayon it wraps. Finally, you would need to test that each crayon color is unique.</p>
-<code><pre>public class BoxOfCrayonsCase {
+```
+public class BoxOfCrayonsCase {
[Test]
public function shouldHaveTwelveCrayons():void {}
[Test]
@@ -63,7 +64,8 @@ public class WrapperCase {
public function shouldHaveColorName():void {}
[Test]
public function shouldMatchWrappedCrayon():void {}
-}</pre></code>
+}
+```
<p>You now have a road map for testing. Currently none of these tests actually verify functionality. As noted previously, the lack of a failing assertion is a success so all of these tests would pass. Excellent, testing complete!</p>
<p>If only the world were so easy. In reality, these tests are far from complete, the fact that all these <i>incomplete</i> tests will pass is a problem that needs to be addressed.</p>
@@ -98,9 +100,11 @@ public class WrapperCase {
<li>Are easily identified and ignored through the <code>[Ignore]</code> decoration</li>
</ul>
-<code><pre>[Ignore]
+```
+[Ignore]
[Test]
-public function ignoreTest() :void</pre></code>
+public function ignoreTest() :void
+```
<h2>Walkthrough 1: Commenting out and Ignoring Tests</h2>
@@ -120,7 +124,6 @@ public function ignoreTest() :void</pre></code>
</li>
<li>
<p>Highlight the text that comprises the <code>shouldGetBottomPointOnCircle()</code> function. Press Shift+Control+c (Shift+Command+C on MacOS) and the comment markers (/* and */) should be added as shown.</p>
-
<img alt='CommentingCode' id='shift' src='../images/unit5/image1.png' />
<p class='caption' id='shift'>Figure 1: Commenting code</p>
</li>
@@ -141,14 +144,16 @@ public function ignoreTest() :void</pre></code>
</li>
<li>
<p>Add a line with <code>[Ignore]</code> metadata above the <code>[Test]</code> metadata of the <code>shouldGetBottomPointOnCircle()</code> function.</p>
-
- <code><pre>[Ignore]
+
+```
+[Ignore]
[Test]
public function shouldGetBottomPointOnCircle():void {
...
-} </pre></code>
+}
+```
- </li>
+</li>
<li>
<p>Save BasicCircleTest.as.</p>
</li>
@@ -162,12 +167,14 @@ public function shouldGetBottomPointOnCircle():void {
<li>
<p>Similarly, mark the <code>shouldGetRightPointOnCircle</code>, <code>shouldGetLeftPointOnCircle()</code> and <code>shouldThrowRangeError()</code> test method with ignore metadata.</p>
- <code><pre>[Ignore]
+```
+[Ignore]
[Test]
public function shouldThrowRangeError():void {
-} </pre></code>
+}
+```
- </li>
+</li>
<li>
<p>Save BasicCircleTest.as</p>
</li>
@@ -186,12 +193,14 @@ public function shouldThrowRangeError():void {
<p>The [Ignore] metadata provides a few additional benefits over commenting. First, the [Ignore] metadata can accept additional system and user defined arguments.</p>
<p>For example:</p>
-<code><pre>[Ignore(description="Phase II Requirement",category="Required"]
+```
+[Ignore(description="Phase II Requirement",category="Required"]
[Test]
public function shouldGetPointsOnCircle():void
{
...
-}</pre></code>
+}
+```
<p>This additional information can be used for filtering, sorting and reporting on some test systems. Unfortunately, at this time, Flash Builder does not display this extra information to its users. However, it does provide one useful function when using [Ignore]: Flash Builder Premium will display the ignored tests in the case hierarchy. This means you can easily find and click on an ignored method to quickly find it in a large project.</p>
@@ -215,9 +224,17 @@ public function shouldGetPointsOnCircle():void
<p>Standard assertions work well for many cases. However, as the complexity of your tests increases, you may find yourself with long, complicated compound assertions. For example: what if you needed to ensure that the result of a method call was an array that contained at least two specific values?</p>
<p>Ideally, tests not only verify functionality but are also a portion of the documentation for the system. This is only possible if the tests are clear, concise and legible. Further, in cases like the array examples above, you would end up with significant logic in your tests. Any place where logic exists needs to be considered suspect unless there are tests to verify that functionality, and we simply can't recommend writing tests for your tests.</p>
<p>Additionally, the simplistic nature of the assertions you have learned so far, also means they provide simplistic error messages. Take the case of this slightly more complicated assertion that determines if a number is between two other numbers:</p>
-<code><pre>assertTrue( num1 > num2 && num1 < num3 );</pre></code>
+
+```
+assertTrue( num1 > num2 && num1 < num3 );
+```
+
<p>If this test fails, it would yield the basic and uninformative failure message:</p>
-<code><pre>"Expected <true> but was <false>."</pre></code>
+
+```
+"Expected <true> but was <false>."
+```
+
<p>This information, while true, is not all that useful for instant problem identification. This lack of information forces the developer back to the original test to understand what was being tested and helps defeat one of the key advantages of having tests.</p>
<h2>Hamcrest</h2>
@@ -225,17 +242,37 @@ public function shouldGetPointsOnCircle():void
<p>Hamcrest is an open source library of matchers, which are simple classes that perform comparisons. These matchers, along with encompassing logic, allow Hamcrest to perform complicated matching with a simple and extensible syntax.</p>
<p>Hamcrest itself is neither a unit testing library, nor specifically made to work with unit tests, but the matchers it exposes are used by FlexUnit to provide a powerful and flexible way to move beyond basic assertions.</p>
<p>When using Hamcrest assertions in FlexUnit, you use a special function named <code>assertThat()</code>.</p>
-<code><pre>public function assertThat( value, matcher );</pre></code>
+
+```
+public function assertThat( value, matcher );
+```
+
<p>Unlike the assertions used so far, the <code>assertThat()</code> method does not inherently prescribe any specific type of comparison or evaluation. Instead, you provide a value and a matcher. It is the matcher that dictates the type of comparison.</p>
<p>Referring back to the example from above, if you wished to know if num1 was between num2 and num3 using standard assert syntax, you would write:</p>
-<code><pre>assertTrue( num2 < num1 && num1 < num3);</pre></code>
+
+```
+assertTrue( num2 < num1 && num1 < num3);
+```
+
<p>Using Hamcrest, this same assertion would read:</p>
-<code><pre>assertThat( num1, is( between( num2, num3 ) ) );</pre></code>
+
+```
+assertThat( num1, is( between( num2, num3 ) ) );
+```
+
<p>There are several advantages to the Hamcrest assertion. First, this statement could be read by someone with little testing or development experience and would still be understandable.</p>
<p>Second, if the <code>assertThat()</code> statement above fails it would yield the following result:</p>
-<code><pre>"Expected a number between <num2> and <num3> but was <num1>."</pre></code>
+
+```
+"Expected a number between <num2> and <num3> but was <num1>."
+```
+
<p>which is many, many times more useful than the <code>assertTrue()</code> statement's failure message in this same situation:</p>
-<code><pre>"Expected <true> but was <false>."</pre></code>
+
+```
+"Expected <true> but was <false>."
+```
+
<p>This particular assertion uses the <code>is()</code> and <code>between()</code> matchers to create a more readable assertion. These are just two of the many types of matchers offered by Hamcrest. Further, as each matcher is simply a class that implements a specific interface, you are encouraged to create your own matchers to make even the most difficult matching clear inside of your test cases.</p>
<p>For more information on Hamcrest and extensible matchers, check out the Hamcrest-as3 page on github available at <a class='contentlink' href='https://github.com/drewbourne/hamcrest-as3' target='_blank'>https://github.com/drewbourne/hamcrest-as3</a>.</p>
@@ -244,26 +281,30 @@ public function shouldGetPointsOnCircle():void
<p>There were three test failures in Unit 4: Walkthrough 3 because the <code>assertEquals()</code> statement is used to judge equality, which seems logical on the surface. However, there are many times when a computer's concept of equal and our concept of 'equal enough' are not the same.</p>
<p>The <code>shouldGetTopPointOnCircle()</code> method was the only one of the four point tests that passed:</p>
-<code><pre>[Test]
+```
+[Test]
public function shouldGetTopPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( 0 );
assertEquals( 5, point.x );
assertEquals( 0, point.y );
-}</pre></code>
+}
+```
<p>This was the only of the four new point tests that called <code>circle.getPointOnCircle()</code> with an argument of 0. The other three point tests called <code>circle.getPointOnCircle()</code> with <code>Math.PI/2</code>, <code>Math.PI</code>, and <code>(3*Math.PI)/2</code>.</p>
<p>Pi is an irrational number that cannot be expressed exactly. Further, Flash Player itself can only store large numbers to a certain precision. This means that calculations involving any floating point value, and especially an irrational one like Pi, will always have a margin of error.</p>
-<code><pre>[Test]
+```
+[Test]
public function shouldGetBottomPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( Math.PI );
assertEquals( -5, point.x );
assertEquals( 0, point.y );
-}</pre></code>
+}
+```
<img alt='FailureStackTrace' src='../images/unit5/image5.png' />
<p class='caption'>Figure 1: Failure Stack Trace</p>
@@ -288,37 +329,50 @@ public function shouldGetBottomPointOnCircle():void {
<li>
<p>Open the FlexUnit4Training.mxml file from the previous exercise.</p>
<p>Alternatively, if you didn't complete the previous lesson or your code is not functioning properly, you can import the FlexUnit4Training_wt2.fxp project from the Unit 5/Start folder. Please refer to Unit 2: Walkthrough 1 for instructions on importing a Flash Builder project.</p>
-
<h3><br />Using the assertThat() method with extensible assertions</h3>
-
</li>
<li>
<p>At the top of the <code>BasicCircleTest</code> class declare a private, static constant with the name of <code>TOLERANCE</code> and a data type of <code>Number</code>. Set the constant equal to <code>.0001</code>.</p>
-
- <code><pre>public class BasicCircleTest {
+
+```
+public class BasicCircleTest {
private static const TOLERANCE:Number = .0001;
...
-} </pre></code>
+}
+```
- <p>We will use this value to determine "close enough." If the result is between our expected value plus or minus the tolerance, we are willing to consider the value to be close enough.</p>
+<p>We will use this value to determine "close enough." If the result is between our expected value plus or minus the tolerance, we are willing to consider the value to be close enough.</p>
</li>
<li>
<p>Replace the first <code>assertEquals()</code> assertion of the <code>shouldgetTopPointOnCircle()</code> function with the <code>assertThat()</code> statement as shown.</p>
<p>Replace this statement:</p>
- <code><pre>assertEquals( 5, point.x );</pre></code>
- <p>With this statement:</p>
- <code><pre>assertThat( point.x, closeTo( 5, TOLERANCE ) );</pre></code>
- <p>Be sure to either use the code complete with assertThat and closeTo, or manually add their imports.</p>
- <code><pre>import org.flexunit.assertThat;<br />import org.hamcrest.number.closeTo;</pre></code>
- </li>
+
+```
+assertEquals( 5, point.x );
+```
+
+<p>With this statement:</p>
+
+```
+assertThat( point.x, closeTo( 5, TOLERANCE ) );
+```
+
+<p>Be sure to either use the code complete with assertThat and closeTo, or manually add their imports.</p>
+
+```
+import org.flexunit.assertThat;<br />import org.hamcrest.number.closeTo;
+```
+
+</li>
<li>
<p>Remove [Ignore] metadata from the <code>shouldGetBottomPointOnCircle()</code>, <code>shouldGetLeftPointOnCircle()</code> and <code>shouldGetRightPointOnCircle()</code> methods.</p>
<p>Unlike <code>assertEquals()</code>, the <code>closeTo()</code> Hamcrest matcher specifies that we need to look for numerical equivalence within a specific margin of error.</p>
</li>
<li>
<p>Change all the point tests so that each uses the <code>assertThat()</code> statement in place of <code>assertEquals()</code>.</p>
-
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetTopPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
@@ -356,9 +410,10 @@ public function shouldGetLeftPointOnCircle():void {
point = circle.getPointOnCircle( (3*Math.PI)/2 );
assertThat( point.x, closeTo( 0, TOLERANCE ) );
assertThat( point.y, closeTo( -5, TOLERANCE ) );
-} </pre></code>
+}
+```
- </li>
+</li>
<li>
<p>Save the BasicCircleTest.as file.</p>
</li>
@@ -375,12 +430,16 @@ public function shouldGetLeftPointOnCircle():void {
<p>The Hamcrest library includes base matchers to cover a wide variety of potential situations. You are encouraged to create your own custom matchers when encountering a situation that can be handled more easily, or more clearly, with a new matcher.</p>
<p>One of the goals behind Hamcrest is to create highly readable matching. If you examine your unit tests, they are still legible but becoming less so as the complexity of testing increases. For example:</p>
-<code><pre> assertThat( point.x, closeTo( -5, TOLERANCE ) );
- assertThat( point.y, closeTo( 0, TOLERANCE ) );</pre></code>
+```
+assertThat( point.x, closeTo( -5, TOLERANCE ) );
+assertThat( point.y, closeTo( 0, TOLERANCE ) );
+```
<p>Neither you, nor another individual that may read this code later, really cares that the point's x and y properties are within a tolerance. What you really care about is that one Point is close to another Point within a given tolerance.</p>
-<code><pre> assertThat( point, closeToPoint( otherPoint, TOLERANCE ) );</pre></code>
+```
+assertThat( point, closeToPoint( otherPoint, TOLERANCE ) );
+```
<p>While this is a simple example, custom matchers continue to become more effective as the complexity of your tests grows.</p>
<p>Custom matcher classes extend the <code>TypeSafeMatcher</code> class. Basic custom matchers are written with three methods.</p>
@@ -443,44 +502,67 @@ public function shouldGetLeftPointOnCircle():void {
</li>
<li>
<p>Add a private variable named <code>point</code> of type <code>Point</code> and another named <code>tolerance</code> of data type <code>Number</code> to the class.</p>
- <code><pre> private var point:Point;
- private var tolerance:Number;</pre></code>
- <p>If you did not use code-completion, add the import for flash.geom.Point at this time.</p>
+
+```
+private var point:Point;
+private var tolerance:Number;
+```
+
+<p>If you did not use code-completion, add the import for flash.geom.Point at this time.</p>
</li>
<li>
<p>Modify the automatically created <code>CloseToPointMatcher()</code> constructor. To accept point and tolerance parameters, instead of an <code>expectedType</code>. Pass a reference of the Point class to the superclass's constructor, and populate the local circle and offset properties with the appropriate argument from the constructor.</p>
- <code><pre>public function CloseToPointMatcher( point:Point, tolerance:Number ) {
+
+```
+public function CloseToPointMatcher( point:Point, tolerance:Number ) {
super(Point);
this.point = point;
this.tolerance = tolerance;
-} </pre></code>
- <p>The <code>super(Point)</code> declaration is informing the classes the data types that the class will be dealing with is a Point class.</p>
+}
+```
+
+<p>The <code>super(Point)</code> declaration is informing the classes the data types that the class will be dealing with is a Point class.</p>
</li>
<li>
<p>Override the <code>matchesSafely()</code> method of the class. It will take an argument named <code>item</code> of data type <code>Object</code>, and will return a Boolean.</p>
- <code><pre>override public function matchesSafely(item:Object):Boolean {
-} </pre></code>
- </li>
+
+```
+override public function matchesSafely(item:Object):Boolean {
+}
+```
+
+</li>
<li>
<p>In the <code>matchesSafely()</code> method, declare a variable named <code>distance</code> of data type <code>Number</code>. Set it equal to <code>Point.distance( item as Point, point )</code>;</p>
- <code><pre>override public function matchesSafely(item:Object):Boolean {
+
+```
+override public function matchesSafely(item:Object):Boolean {
var distance:Number = Point.distance( item as Point, point );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a return statement that checks if the <code>tolerance</code> subtracted from the absolute value of the <code>distance</code> is less than 0.</p>
- <code><pre>override public function matchesSafely(item:Object):Boolean {
+
+```
+override public function matchesSafely(item:Object):Boolean {
var distance:Number = Point.distance( item as Point, point );
return( Math.abs( distance ) - tolerance < 0 );
-} </pre></code>
-
- </li>
+}
+```
+
+</li>
<li>
<p>Add an override for the public function <code>describeTo()</code>. It will take an argument named <code>description</code> of type <code>Description</code>. Because there are two available <code>Description</code> classes, make sure to choose the <code>org.hamcrest.Description</code> class when you use code completion.</p>
- <code><pre>override public function describeTo(description:Description):void {
+
+```
+override public function describeTo(description:Description):void {
description.appendText( "point " ).appendText( point.toString() );
-} </pre></code>
- <p>If you did not use code-completion, add the import for <code>org.hamcrest.Description</code>.</p>
+}
+```
+
+<p>If you did not use code-completion, add the import for <code>org.hamcrest.Description</code>.</p>
</li>
<li>
<p>Save CloseToPointMatcher.as.</p>
@@ -490,18 +572,28 @@ public function shouldGetLeftPointOnCircle():void {
</li>
<li>
<p>Modify the <code>shouldGetTopPointOnCircle()</code> method so that it reads as follows.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetTopPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( 0 );
assertThat( point, new CloseToPointMatcher( new Point( 5, 0 ), TOLERANCE ) );
-} </pre></code>
- <p>Be sure to either choose CloseToPointMatcher from the code-completion, or manually add the import:</p>
- <code><pre>import matcher.CloseToPointMatcher;</pre></code>
- </li>
+}
+```
+
+<p>Be sure to either choose CloseToPointMatcher from the code-completion, or manually add the import:</p>
+
+```
+import matcher.CloseToPointMatcher;
+```
+
+</li>
<li>
<p>Each of the point testing functions should follow this format. Instantiate the circle, instantiate the expected point, and finish with the assertion.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldGetTopPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( 0 );
@@ -524,8 +616,10 @@ public function shouldGetLeftPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( (3*Math.PI)/2 );
assertThat( point, new CloseToPointMatcher( new Point( 0, -5 ), TOLERANCE ) );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save BasicCircleTest.as</p>
</li>
@@ -544,11 +638,14 @@ public function shouldGetLeftPointOnCircle():void {
<p>FlexUnit 4 simplifies this process by allowing an <i>expects</i> argument in the Test annotation for this purpose.</p>
<ul>
<li>To use the <i>expects</i> annotation, simply provide the type of error expected.</li>
- <code><pre>
+
+```
[Test (expects="full.package.ThrownError")]
public function testError():void {}
- </pre></code>
- <li>If the tested method throws the <code>ThrownError</code>, FlexUnit 4.x will recognize this method as a success and mark the test as passed.</li>
+
+```
+
+<li>If the tested method throws the <code>ThrownError</code>, FlexUnit 4.x will recognize this method as a success and mark the test as passed.</li>
<li>If the error is not thrown, then the test is marked as a failure.</li>
<li>If the method throws an error that is not of type <code>ThrownError</code> then FlexUnit 4 marks that test as a failure, since the expected error type did not match the error that was thrown, and something else is causing your method to fail.</li>
</ul>
@@ -573,11 +670,15 @@ public function testError():void {}
</li>
<li>
<p>At the end of the <code>BasicCircleTest</code> class there is an ignored test method named <code>shouldThrowRangeError()</code>. Remove the <code>[Ignore]</code> metadata from this function and declare a variable named <code>someCircle</code> of type <code>Circle</code>. Instantiate the <code>Circle</code> with an origin of <code>(10, 10)</code> and a radius of <code>-5</code>.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldThrowRangeError():void {
var someCircle:Circle = new Circle( new Point( 10, 10 ), -5 );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save BasicCircleTest.as</p>
</li>
@@ -593,11 +694,15 @@ public function shouldThrowRangeError():void {
</li>
<li>
<p>Return to the BasicCircleTest class. Modify the <code>[Test]</code> metadata tag on the line above the <code>shouldThrowRangeError()</code> function to indicate that it expects a <code>RangeError</code>.</p>
- <code><pre>[Test(expects="RangeError")]
+
+```
+[Test(expects="RangeError")]
public function shouldThrowRangeError():void {
var someCircle:Circle = new Circle( new Point( 10, 10 ), -5 );
-} </pre></code>
- <p>RangeError exists in the default package, and hence appears to just be the class name. For your own custom errors or errors defined in the Flex framework, it is important you provide the full path.</p>
+}
+```
+
+<p>RangeError exists in the default package, and hence appears to just be the class name. For your own custom errors or errors defined in the Flex framework, it is important you provide the full path.</p>
</li>
<li>
<p>Save BasicCircleTest.as</p>
diff --git a/content/flexunit/tutorial/flexunit/Unit-6.md b/content/flexunit/tutorial/flexunit/Unit-6.md
index 04616ac..038b953 100644
--- a/content/flexunit/tutorial/flexunit/Unit-6.md
+++ b/content/flexunit/tutorial/flexunit/Unit-6.md
@@ -36,9 +36,11 @@ Title: Unit 6 - Working with the Test Fixture
<li>To use, simply decorate the method with <code>[Before]</code> metadata.</li>
</ul>
-<code><pre>[Before]
+```
+[Before]
public function runMeBeforeEveryTest():void {
-}</pre></code>
+}
+```
<h3>After methods</h3>
@@ -50,23 +52,27 @@ public function runMeBeforeEveryTest():void {
<li>To use, simply decorate the method with <code>[After]</code> metadata.</li>
</ul>
-<code><pre>[After]
+```
+[After]
public function runMeAfterEveryTest():void {
-}</pre></code>
+}
+```
<h3>Order of Execution</h3>
<p>As indicated above Before and After methods run before and after every test. Therefore, the execution of a method with three tests is indicated below:</p>
-<code><pre> [Before]
- [Test1]
- [After]
- [Before]
- [Test2]
- [After]
- [Before]
- [Test3]
- [After]</pre></code>
+```
+[Before]
+ [Test1]
+[After]
+[Before]
+ [Test2]
+[After]
+[Before]
+ [Test3]
+[After]
+```
<p>The setup of your test fixture occurs before each test to ensure the test runs in isolation from others in the test case.</p>
@@ -93,44 +99,66 @@ public function runMeAfterEveryTest():void {
</li>
<li>
<p>Add a private variable with the name of <code>circle</code> and a data type of <code>Circle</code> to the class.</p>
- <code><pre>public class BasicCircleTest {
- private static const TOLERANCE:Number = .0001;
- private var circle:Circle;
- ...
-} </pre></code>
- </li>
+
+```
+public class BasicCircleTest {
+ private static const TOLERANCE:Number = .0001;
+ private var circle:Circle;
+ ...
+}
+```
+
+</li>
<li>
<p>Add a public function named <code>setMeUp()</code> to the class. Mark the function with a <code>[Before]</code> metadata tag. This function will set the <code>circle</code> property to a new <code>Circle</code> instance with arguments <code>new Point( 0, 0 )</code> and <code>5</code>.</p>
- <code><pre>[Before]
+
+```
+[Before]
public function setMeUp():void {
circle = new Circle( new Point( 0, 0 ), 5 );
-} </pre></code>
- <p>Note, the name of the function is unimportant. It is only the Before metadata that makes this a Before method.</p>
+}
+```
+
+<p>Note, the name of the function is unimportant. It is only the Before metadata that makes this a Before method.</p>
</li>
<li>
<p>Similarly, add another public function named <code>tearMeDown()</code>. In this case you are going to mark the function with an <code>[After]</code> metadata tag. This function will set the class <code>circle</code> variable to null.</p>
- <code><pre>[After]
+
+```
+[After]
public function tearMeDown():void {
circle = null;
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Remove the <code>circle</code> variable instantiations from each of the test methods. Using the first test as a model:</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldReturnProvidedRadius():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
assertEquals( 5, circle.radius );
-} </pre></code>
- <p>Becomes:</p>
- <code><pre>[Test]
+}
+```
+
+<p>Becomes:</p>
+
+```
+[Test]
public function shouldReturnProvidedRadius():void {
assertEquals( 5, circle.radius );
-} </pre></code>
- <h3><br />Running the test case</h3>
+}
+```
+
+<h3><br />Running the test case</h3>
</li>
<li>
<p>After the instantiations have been removed, the test class should read as follows:</p>
- <code><pre>public class BasicCircleTest {
+
+```
+public class BasicCircleTest {
private static const TOLERANCE:Number = .0001;
private var circle:Circle;
[Before]
@@ -193,8 +221,10 @@ public function shouldReturnProvidedRadius():void {
public function shouldThrowRangeError():void {
var someCircle:Circle = new Circle( new Point( 10, 10 ), -5 );
}
-} </pre></code>
- <p>Other circles, such as <code>circle2</code> are still instantiated in its respective methods, because it is unique in each case.</p>
+}
+```
+
+<p>Other circles, such as <code>circle2</code> are still instantiated in its respective methods, because it is unique in each case.</p>
</li>
<li>
<p>Save BasicCircleTest.as.</p>
@@ -228,7 +258,8 @@ public function shouldReturnProvidedRadius():void {
<p>As items created in BeforeClass are created before the test case constructor is called, they must be static. Unlike items created in Before which have the possibility of being garbage collected, these static items will not. Therefore, the cleanup performed by the AfterClass methods is extremely important.</p>
<p>Static functions marked with [BeforeClass] and [AfterClass] can exist on a test case or a test suite and are run once per execution. The method execution of a three-test hierarchy is illustrated below:</p>
-<code><pre>[BeforeClass]
+```
+[BeforeClass]
[Before]
[Test]
[After]
@@ -238,7 +269,8 @@ public function shouldReturnProvidedRadius():void {
[Before]
[Test]
[After]
-[AfterClass]</pre></code>
+[AfterClass]
+```
<h2>Walkthrough 2: Using BeforeClass and AfterClass</h2>
@@ -257,22 +289,32 @@ public function shouldReturnProvidedRadius():void {
</li>
<li>
<p>Declare a public static function named <code>setUpClass()</code>, mark it with <code>[BeforeClass]</code> metadata. In the function body, add a trace statement that merely states "Before Class."</p>
- <code><pre>[BeforeClass]
+
+```
+[BeforeClass]
public static function setUpClass():void {
trace( "Before Class" );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Similarly, declare another public static function named <code>tearDownClass()</code>, mark it with <code>[AfterClass]</code> metadata.</p>
- <code><pre>[AfterClass]
+
+```
+[AfterClass]
public static function tearDownClass():void {
trace( "After Class" );
-} </pre></code>
- <h3><br />Visualizing test order</h3>
+}
+```
+
+<h3><br />Visualizing test order</h3>
</li>
<li>
<p>A similar trace statement should be added to the existing <code>setMeUp()</code> and <code>tearMeDown()</code> methods.</p>
- <code><pre>[Before]
+
+```
+[Before]
public function setMeUp():void {
circle = new Circle( new Point( 0, 0 ), 5 );
trace( "Before Test" );
@@ -281,16 +323,22 @@ public function setMeUp():void {
public function tearMeDown():void {
circle = null;
trace( "After Test" );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Finally, add a trace statement to every test method on the first line.</p>
- <code><pre>[Test]
+
+```
+[Test]
public function shouldReturnProvidedRadius():void {
trace( "Test" );
assertEquals( 5, circle.radius );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save BasicCircleTest.as</p>
</li>
@@ -306,7 +354,8 @@ public function shouldReturnProvidedRadius():void {
</li>
<li>
<p>Take a look at the console view; if all the functions ran to completion, you should see the following show up in order.</p>
- <code><pre>
+
+```
Before Class
Before Test
Test
@@ -342,8 +391,10 @@ Before Test
Test
After Test
After Class
- </pre></code>
- </li>
+
+```
+
+</li>
<li>
<p>Based on the exhibited call hierarchy, you should be able to tell that the <code>setUpClass()</code> and <code>tearDownClass()</code> functions are being called before the first test method and after the last. Meanwhile, the <code>setMeUp()</code> and <code>tearMeDown()</code> methods are being called respectively before and after every test.</p>
</li>
diff --git a/content/flexunit/tutorial/flexunit/Unit-7.md b/content/flexunit/tutorial/flexunit/Unit-7.md
index e977856..25d4245 100644
--- a/content/flexunit/tutorial/flexunit/Unit-7.md
+++ b/content/flexunit/tutorial/flexunit/Unit-7.md
@@ -33,14 +33,16 @@ Title: Unit 7 - Using Suites
<p>The suite runner is org.flexunit.runners.Suite. This runner interrogates a class looking for each public variable. It determines the type (Class) of the variable and attempts to run that class.</p>
<p>While it is possible to sort the order of suites and test cases, by default the order in which they execute is indeterminate and not governed by the order of their definition in the suite class.</p>
-<code><pre>[Suite]
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class SampleSuite {
public var testCase:TestCase;
public var anotherTestCase:AnotherTestCase;
public var yetAnotherTestCase:YetAnotherTestCase;
public var anotherSuite:AnotherSuite;
-}</pre></code>
+}
+```
<h2>Walkthrough 1: Creating a new case for the Constructor Test</h2>
@@ -72,14 +74,20 @@ public class SampleSuite {
</li>
<li>
<p>Remove the automatically created constructor from the new ActionScript class, so that it reads as shown.</p>
- <code><pre>package math.testcases {
+
+```
+package math.testcases {
public class CircleConstructorTest {
}
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Highlight and cut the <code>shouldThrowRangeError()</code> method from the BasicCircleTest.as file and paste it into the CircleConstructorTest class.</p>
- <code><pre>public class CircleConstructorTest {
+
+```
+public class CircleConstructorTest {
[Test(expects="RangeError")]
public function shouldThrowRangeError():void {
trace("Test");
@@ -87,8 +95,10 @@ public class SampleSuite {
new Circle( new Point( 10, 10 ), -5 );
}
}
- </pre></code>
- <p>Because you cut and pasted the above function into a new class you will need to manually add the appropriate import statements.</p>
+
+```
+
+<p>Because you cut and pasted the above function into a new class you will need to manually add the appropriate import statements.</p>
</li>
<li>
<p>Add the import statements for <code>flash.geom.Point</code> and <code>net.digitalprimates.math.Circle</code> to the class.</p>
@@ -98,7 +108,9 @@ public class SampleSuite {
</li>
<li>
<p>Save the CircleConstructorTest.as and the BasicCircleTest.as files.</p>
- <code><pre>package flexUnitTests.cases {
+
+```
+package flexUnitTests.cases {
import flash.geom.Point;
import net.digitalprimates.math.Circle;
public class CircleConstructorTest {
@@ -108,8 +120,10 @@ public class SampleSuite {
new Circle( new Point( 10, 10 ), -5 );
}
}
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Run the FlexUnit4Training.mxml file.</p>
<p>If FlexUnit4Training.mxml ran successfully you should see the following output in your browser window:</p>
@@ -125,22 +139,26 @@ public class SampleSuite {
<p>Suites are simply ActionScript class files with public properties. The class is decorated with two very important pieces of metadata. First, the [Suite] tag, which tells Flash Builder and FlexUnit that this class is intended to be a test suite.</p>
<p>Second, the [RunWith] metadata tells FlexUnit to use the org.flexunit.runners.Suite class to execute this class. You will learn more about extensibility and the [RunWith] metadata later in this unit.</p>
-<code><pre>[Suite]
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
-public class mySuite</pre></code>
+public class mySuite
+```
<h3>Test cases within suites</h3>
<p>Within a test suite, all the test cases and other suites are represented by public properties within the class. The sample suite below includes three test cases and additional suite.</p>
-<code><pre>[Suite]
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class MySuite {
public var testCase:TestCase;
public var anotherTestCase:AnotherTestCase;
public var yetAnotherTestCase:YetAnotherTestCase;
public var anotherSuite:AnotherSuite;
-}</pre></code>
+}
+```
<p>The <code>anotherSuite</code> variable is another suite that can contain any number of tests and suites. There is no limit to the hierarchy of test suites and each level of suite is only aware of its immediate children</p>
<p>An empty suite (one with no tests or no public tests or suites) will throw an <code>InitializationError</code>.</p>
@@ -177,31 +195,47 @@ public class MySuite {
</li>
<li>
<p>Remove the automatically created constructor from the new ActionScript class. Mark the class with <code>[Suite]</code> and <code>[RunWith(" org.flexunit.runners.Suite")]</code> metadata tags, which should be placed above the class declaration.</p>
- <code><pre>[Suite]
+
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class CircleSuite {
...
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a public variable named <code>test1</code> of type <code>BasicCircleTest</code> and another public variable named <code>test2</code> of type <code>CircleConstructorTest</code> to the class.</p>
- <code><pre>[Suite]
+
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class CircleSuite {
public var test1:BasicCircleTest;
public var test2:CircleConstructorTest;
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Open the FlexUnit4Training.mxml file.</p>
</li>
<li>
<p>Look under the <code><fx:Script></code> block.</p>
<p>Replace this line:</p>
- <code><pre>testsToRun.push( BasicCircleTest );</pre></code>
- <p>with this line:</p>
- <code><pre>testsToRun.push( CircleSuite );</pre></code>
- <p>If you did not use code completion, add the import for testcases.CircleSuite at this time.</p>
+
+```
+testsToRun.push( BasicCircleTest );
+```
+
+<p>with this line:</p>
+
+```
+testsToRun.push( CircleSuite );
+```
+
+<p>If you did not use code completion, add the import for testcases.CircleSuite at this time.</p>
</li>
<li>
<p>Save FlexUnit4Training.mxml.</p>
@@ -239,7 +273,8 @@ public class CircleSuite {
<img alt='TestStructure' src='../images/unit7/image7.png' />
<p>The test structure creates test for a nuclear family. The top level package is testcases, which contains the FamilySuite.as file. Because this application objectifies the nuclear family, the FamilySuite.as file can be arranged accordingly.</p>
-<code><pre>import tests.children.ChildrenSuite;
+```
+import tests.children.ChildrenSuite;
import tests.father.FatherSuite;
import tests.mother.MotherSuite;
[Suite]
@@ -248,7 +283,8 @@ public class FamilySuite {
public var fatherSuite:FatherSuite;
public var motherSuite:MotherSuite;
public var childrenSuite:ChildrenSuite;
-}</pre></code>
+}
+```
<p>This is a valid suite despite the fact that it only contains other suites and does not directly contain any test cases.</p>
<ul>
diff --git a/content/flexunit/tutorial/flexunit/Unit-8.md b/content/flexunit/tutorial/flexunit/Unit-8.md
index d90b0a4..0a6ce07 100644
--- a/content/flexunit/tutorial/flexunit/Unit-8.md
+++ b/content/flexunit/tutorial/flexunit/Unit-8.md
@@ -37,13 +37,15 @@ Title: Unit 8 - FlexUnit Theories
<p>If a test succeeds in two cases with two different values, already it has exponentially more assurance. If a test succeeds three or more times with three or more values, for each trial added it becomes substantially easier to trust the functionality being tested.</p>
<p>A small range of values is acceptable. Granted, it does not cover every case, but it does give you a substantial degree of assurance. A small range of values can also include all the types of values that could be problematic. For instance:</p>
-<code><pre>public function absoluteValue( value:int ):int {
+```
+public function absoluteValue( value:int ):int {
if ( value < 0 ) {
return value * -1;
} else {
return value;
}
-}</pre></code>
+}
+```
<p>A simple method like the one presented above should be tested with at least five values: Positive integers, negative integers, 0, NaN, Infinity. That kind of small combination is fairly standard for arithmetic functions, but sometimes it becomes more complicated, particularly when float types are involved in the calculation.</p>
<p>While you may not be able to test every case, the more potential values that can be passed through the method to more assurance you have that the method does indeed function directly. We call this concept triangulation.</p>
@@ -54,8 +56,10 @@ Title: Unit 8 - FlexUnit Theories
<p>Any one case that fails disproves the whole theory. Therefore any one time the theory method is called when it fails marks the entire test as a failure.</p>
<p>A simple theory method:</p>
-<code><pre>[Theory]
-public function testTheory( value1:Number, value2:Number ):void</pre></code>
+```
+[Theory]
+public function testTheory( value1:Number, value2:Number ):void
+```
<h2>Understanding the use case for data points</h2>
@@ -71,8 +75,10 @@ public function testTheory( value1:Number, value2:Number ):void</pre></code>
</ul>
<p>For Instance:</p>
-<code><pre>[DataPoint]
-public static var value1:int = 10;</pre></code>
+```
+[DataPoint]
+public static var value1:int = 10;
+```
<p>Data points are an array of variables, or a function that returns an array, used as arguments to a theory. Data points allow you to quickly specify many values that will be passed to a single theory.</p>
<ul>
@@ -82,9 +88,11 @@ public static var value1:int = 10;</pre></code>
</ul>
<p>For instance:</p>
-<code><pre>[DataPoints]
+```
+[DataPoints]
[ArrayElementType("String")]
-public static var stringValues:Array = ["one","two","three" ];</pre></code>
+public static var stringValues:Array = ["one","two","three" ];
+```
<p>The ArrayElementType metadata describes the type of data in the Array to the theories in this class.</p>
@@ -99,28 +107,34 @@ public static var stringValues:Array = ["one","two","three" ];</pre></code>
<li>They run with a special Theory runner</li>
</ul>
-<code><pre>[RunWith("org.flexunit.experimental.theories.Theories")]
+```
+[RunWith("org.flexunit.experimental.theories.Theories")]
public class MyTheoryTest {
-}</pre></code>
+}
+```
<p>Theories run with all matching data points. If any combination of <code>Datapoints</code> fail, the theory fails.</p>
-<code><pre>[DataPoints]
+```
+[DataPoints]
[ArrayElementType("Number")]
public static var radii:Array = [ 1, 2, 3, 4 ];
[Theory]
-public function testTheory( value1:Number, value2:Number ):void</pre></code>
+public function testTheory( value1:Number, value2:Number ):void
+```
<p>This theory takes two parameters. All <code>Datapoints</code> referenced with the data type integer will be passed into each of these values for every possible combination.</p>
<p>Test process:</p>
-<code><pre>testTheory( 1, 1 )
+```
+testTheory( 1, 1 )
testTheory( 1, 2 )
testTheory( 1, 3 )
...
testTheory( 4, 3 )
-testTheory( 4, 4 )</pre></code>
+testTheory( 4, 4 )
+```
<h2>Discussion on data typing and conversion</h2>
@@ -148,12 +162,14 @@ public function testNamesAndNumbers( name:String, numberOne:Number, numberTwo:Nu
<p>Numbers from the number array are used in the numberOne and numberTwo parameters, and the array of strings is used for the name parameter. The theory runs with all possible input combinations.</p>
-<code><pre>testNamesAndNumbers( "Mike", 1, 1 )
+```
+testNamesAndNumbers( "Mike", 1, 1 )
testNamesAndNumbers( "Mike", 1, 2 )
testNamesAndNumbers( "Mike", 1, 3 )
...
testNamesAndNumbers( "Cindy", 5, 4 )
-testNamesAndNumbers( "Cindy", 5, 5 )</pre></code>
+testNamesAndNumbers( "Cindy", 5, 5 )
+```
<h2>Walkthrough 1: Creating a Circle Theory</h2>
@@ -178,59 +194,87 @@ testNamesAndNumbers( "Cindy", 5, 5 )</pre></code>
</li>
<li>
<p>Mark the new class with <code>[RunWith("org.flexunit.experimental.theories.Theories")]</code> metadata, which should be placed just above the class definition.</p>
- <code><pre>[RunWith("org.flexunit.experimental.theories.Theories")]
+
+```
+[RunWith("org.flexunit.experimental.theories.Theories")]
public class CircleTheory {
...
-} </pre></code>
- <h3><br />Creating theories</h3>
+}
+```
+
+<h3><br />Creating theories</h3>
</li>
<li>
<p>Create a new public function named <code>shouldShowAllRadiiEqual()</code> with a parameter named <code>radius</code> of data type <code>Number</code>. Mark the function with <code>[Theory]</code> metadata:</p>
- <code><pre>[Theory]
+
+```
+[Theory]
public function shouldShowAllRadiiEqual( radius:Number ):void {
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a variable named <code>circle</code> of type <code>Circle</code> to the <code>shouldShowAllRadiiEqual()</code> method. Instantiate circle with an origin at <code>(0, 0)</code> and the <code>radius</code> parameter passed in as its radius.</p>
- <code><pre>[Theory]
+
+```
+[Theory]
public function shouldShowAllRadiiEqual( radius:Number ):void {
var circle:Circle = new Circle( new Point( 0, 0 ), radius );
-} </pre></code>
- <p>If you did not use code-completion, add the imports for net.digitalprimates.math.Circle and flash.geom.Point at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the imports for net.digitalprimates.math.Circle and flash.geom.Point at this time.</p>
</li>
<li>
<p>Add a call to the <code>assertEquals()</code> method. Assert that the <code>circle.radius</code> is equal to the <code>radius</code> parameter.</p>
- <code><pre>[Theory]
+
+```
+[Theory]
public function shouldShowAllRadiiEqual( radius:Number ):void {
var circle:Circle = new Circle( new Point( 0, 0 ), radius );
assertEquals( radius, circle.radius );
-} </pre></code>
- <p>If you did not use code-completion, add an import for org.flexunit.asserts.assertEquals at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add an import for org.flexunit.asserts.assertEquals at this time.</p>
</li>
<li>
<p>Add a public static array to the class. Fill it with a variety of positive integer values. Here is an example:</p>
- <code><pre>public static var radii:Array = [ 1,2,3,4,5,6,7,8,9,10 ];</pre></code>
- </li>
+
+```
+public static var radii:Array = [ 1,2,3,4,5,6,7,8,9,10 ];
+```
+
+</li>
<li>
<p>Mark the array with two lines of metadata, <code>[DataPoints]</code> and <code>[ArrayElementType("Number")]</code>.</p>
- <code><pre>[DataPoints]
+
+```
+[DataPoints]
[ArrayElementType("Number")]
-public static var radii:Array = [ 1,2,3,4,5,6,7,8,9,10 ];</pre></code>
- </li>
+public static var radii:Array = [ 1,2,3,4,5,6,7,8,9,10 ];
+```
+
+</li>
<li>
<p>Save CircleTheory.as.</p>
<h3><br />Adding theories to your test suite</h3>
</li>
<li>
<p>Open the CircleSuite.as file within the math.testcases package. Add a new public variable named <code>test3</code> with a type of <code>CircleTheory</code>.</p>
- <code><pre>[Suite]
+
+```
+[Suite]
[RunWith("org.flexunit.runners.Suite")]
public class CircleSuite {
public var test1:BasicCircleTest;
public var test2:CircleConstructorTest;
public var test3:CircleTheory;
-} </pre></code>
- <p>If you did not use code-completion, add the import for math.testcases.CircleTheory at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the import for math.testcases.CircleTheory at this time.</p>
</li>
<li>
<p>Save the CircleSuite.as file.</p>
@@ -255,7 +299,9 @@ public class CircleSuite {
<li>For instance</li>
</ul>
-<code><pre>assumeThat( value, greaterThan(0) );</pre></code>
+```
+assumeThat( value, greaterThan(0) );
+```
<p>If the parameter is greater than 0, the assumption passes and the test moves onto its next line. If the parameter value is not greater than 0 the assumption fails and the runner will move on to the next data point without running any other lines of this test. Even though the assumption fails for values under 0, the test does not fail or throw an error, because those data points have been essentially marked as invalid for the test theory.</p>
@@ -277,8 +323,12 @@ public class CircleSuite {
</li>
<li>
<p>Add a single negative value to the beginning of the class's radii array. Here is an example:</p>
- <code><pre>public static var radii:Array = [ -5,1,2,3,4,5,6,7,8,9,10 ];</pre></code>
- </li>
+
+```
+public static var radii:Array = [ -5,1,2,3,4,5,6,7,8,9,10 ];
+```
+
+</li>
<li>
<p>Run the FlexUnit4Training.mxml file.</p>
<p>If FlexUnit4Training.mxml ran successfully you should see the following output in your browser window:</p>
@@ -289,13 +339,17 @@ public class CircleSuite {
</li>
<li>
<p>Add a new line to the <code>shouldShowAllRadiiEqual()</code> method. On the line, add an assumption indicating that this test only works for positive radii. The method should read as follows:</p>
- <code><pre>[Theory]
+
+```
+[Theory]
public function shouldShowAllRadiiEqual( radius:Number ):void {
assumeThat( radius, greaterThan( 0 ) );
var circle:Circle = new Circle( new Point( 0, 0 ), radius );
assertEquals( radius, circle.radius );
-} </pre></code>
- <p>If you did not use code-completion, add the import statements for org.flexunit.assumeThat and org.hamcrest.number.greaterThan at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the import statements for org.flexunit.assumeThat and org.hamcrest.number.greaterThan at this time.</p>
</li>
<li>
<p>Save the CircleTheory.as file.</p>
@@ -319,9 +373,11 @@ public function shouldShowAllRadiiEqual( radius:Number ):void {
</ul>
<p>For Instance:</p>
-<code><pre>[DataPoints]
+```
+[DataPoints]
[ArrayElementType("flash.geom.Point")]
-Public static var points:Array = [ new Point( 0, 0 ) ];</pre></code>
+Public static var points:Array = [ new Point( 0, 0 ) ];
+```
<h2>Using the constructor of the Theory Case</h2>
@@ -371,69 +427,101 @@ public class TestCase {
</li>
<li>
<p>Add a private static constant named <code>TOLERANCE</code> of data type <code>Number</code> to the CircleTheory class.</p>
- <code><pre>private static const TOLERANCE:Number = .0001;</pre></code>
- </li>
+
+```
+private static const TOLERANCE:Number = .0001;
+```
+
+</li>
<li>
<p>Add a new method named <code>shouldShowAllPointsEqual()</code> to the class.</p>
- <code><pre>[Theory]
+
+```
+[Theory]
public function shouldShowAllPointsEqual(origin:Point):void {
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Create a new circle with the function's origin argument and a radius of 10.</p>
- <code><pre>[Theory]
+
+```
+[Theory]
public function shouldShowAllPointsEqual(origin:Point):void {
var circle:Circle = new Circle(origin, 10);
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Call the <code>circle.getPointOnCircle()</code> method with argument <code>Math.PI</code>.</p>
- <code><pre>[Theory]
+
+```
+[Theory]
public function shouldShowAllPointsEqual( origin:Point ):void {
var circle:Circle = new Circle( origin, 10 );
var pointOnCircle:Point = circle.getPointOnCircle( Math.PI );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Declare a variable named <code>distance</code> of data type <code>Number</code> within the <code>shouldShowAllPointsEqual()</code> method. Instantiate it to <code>Point.distance( origin, pointOnCircle )</code>.</p>
- <code><pre>[Theory]
+
+```
+[Theory]
public function shouldShowAllPointsEqual( origin:Point ):void {
var circle:Circle = new Circle( origin, 10 );
var pointOnCircle:Point = circle.getPointOnCircle( Math.PI );
var distance:Number = Point.distance( origin, pointOnCircle );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Add a call to the <code>assertThat()</code> method. It should assert that <code>distance</code> variable is <code>closeTo( circle.radius, TOLERANCE )</code>.</p>
- <code><pre>[Theory]
+
+```
+[Theory]
public function shouldShowAllPointsEqual( origin:Point ):void {
var circle:Circle = new Circle( origin, 10 );
var pointOnCircle:Point = circle.getPointOnCircle( Math.PI );
var distance:Number = Point.distance( origin, pointOnCircle );
assertThat( distance, closeTo( circle.radius, TOLERANCE ) );
-} </pre></code>
- <p>If you did not use code-completion, add the imports for org.flexunit.assertThat and org.hamcrest.number.closeTo at this time.</p>
+}
+```
+
+<p>If you did not use code-completion, add the imports for org.flexunit.assertThat and org.hamcrest.number.closeTo at this time.</p>
</li>
<li>
<p>Add a new public static array named <code>points</code> to the class. Initialize the array with six point values, representing a gamut of potential points.</p>
- <code><pre>public static var points:Array = [ new Point( 0, 0 ),
- new Point( 10, 10 ),
- new Point( -5, 5 ),
- new Point( 20, -20 ),
- new Point( -17, -16 ),
- new Point( 5.2, -11.3 ) ];</pre></code>
- </li>
+
+```
+public static var points:Array = [ new Point( 0, 0 ),
+ new Point( 10, 10 ),
+ new Point( -5, 5 ),
+ new Point( 20, -20 ),
+ new Point( -17, -16 ),
+ new Point( 5.2, -11.3 ) ];
+```
+
+</li>
<li>
<p>Mark the array with <code>[DataPoints]</code> and <code>[ArrayElementType("flash.geom.Point")]</code> metadata. Place these tags on the two lines above the array:</p>
- <code><pre>[DataPoints]
+
+```
+[DataPoints]
[ArrayElementType("flash.geom.Point")]
public static var points:Array = [ new Point( 0, 0 ),
- new Point( 10, 10 ),
- new Point( -5, 5 ),
- new Point( 20, -20 ),
- new Point( -17, -16 ),
- new Point( 5.2, -11.3 ) ];</pre></code>
- </li>
+ new Point( 10, 10 ),
+ new Point( -5, 5 ),
+ new Point( 20, -20 ),
+ new Point( -17, -16 ),
+ new Point( 5.2, -11.3 ) ];
+```
+
+</li>
<li>
<p>Save CircleTheory.as</p>
</li>
@@ -446,15 +534,19 @@ public static var points:Array = [ new Point( 0, 0 ),
</li>
<li>
<p>Alter the <code>shouldShowAllPointsEqual()</code> method to accept a second parameter named <code>radius</code> of data type <code>Number</code>. The <code>radius</code> parameter will be passed to the circle constructor. You will need to add an <code>assumeThat( radius, greaterThan(0) );</code> statement to the first line of the <code>shouldShowAllPointsEqual()</code> method.</p>
- <code><pre>[Theory]
+
+```
+[Theory]
public function shouldShowAllPointsEqual( origin:Point, radius:Number ):void {
assumeThat( radius, greaterThan( 0 ) );
var circle:Circle = new Circle( origin, radius );
var pointOnCircle:Point = circle.getPointOnCircle( Math.PI );
var distance:Number = Point.distance( origin, pointOnCircle );
assertThat( distance, closeTo( circle.radius, TOLERANCE ) );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save CircleTheory.as</p>
</li>
@@ -472,15 +564,19 @@ public function shouldShowAllPointsEqual( origin:Point, radius:Number ):void {
</li>
<li>
<p>Add a parameter to the <code>shouldShowAllPointsEqual()</code> method named <code>radians</code> of data type <code>Number</code>. Alter the <code>circle.getPointOnCircle()</code> method so that it takes <code>radians</code> as its arguments.</p>
- <code><pre>[Theory]
+
+```
+[Theory]
public function shouldShowAllPointsEqual( origin:Point, radius:Number, radians:Number ):void {
assumeThat( radius, greaterThan( 0 ) );
var circle:Circle = new Circle( origin, radius );
var pointOnCircle:Point = circle.getPointOnCircle( radians );
var distance:Number = Point.distance( origin, pointOnCircle );
assertThat( distance, closeTo( circle.radius, TOLERANCE ) );
-} </pre></code>
- </li>
+}
+```
+
+</li>
<li>
<p>Save CircleTheory.as</p>
</li>
diff --git a/content/flexunit/tutorial/flexunit/Unit-9.md b/content/flexunit/tutorial/flexunit/Unit-9.md
index 320247f..40cecd0 100644
--- a/content/flexunit/tutorial/flexunit/Unit-9.md
+++ b/content/flexunit/tutorial/flexunit/Unit-9.md
@@ -81,12 +81,18 @@ public function fault(info:Object):void {
</ol>
<p>To use an external loader you must instantiate the loader and assign it to a public static variable in the test case. Constructor args are used to provide any additional configuration information to the loader.</p>
-<code><pre>public static var testLoader:IExternalDependencyLoader = new MyLoader(" myData.xml" );</pre></code>
+
+```
+public static var testLoader:IExternalDependencyLoader = new MyLoader(" myData.xml" );
+```
+
<p>You then need to create the datapoints array. However, instead of instantiating the array, as you had in previous lessons, you will specify a loader argument on the DataPoints metadata tag. The runner knows how to handle this attribute and ensure your loader is invoked.</p>
-<code><pre>[DataPoints(loader="testLoader")]
+```
+[DataPoints(loader="testLoader")]
[ArrayElementType("Number")]
-public static var radii:Array;</pre></code>
+public static var radii:Array;
+```
<p>Once the data points are loaded, your test case will use them as if they were statically coded into the test case.</p>
@@ -109,22 +115,34 @@ public static var radii:Array;</pre></code>
</li>
<li>
<p>Add a public static variable named <code>radiiLoader</code> of type <code>RadiiDataHelper</code> to the CircleTheory class. It should instantiate a <code>RadiiDataHelper</code> object with the argument <code>"xml/radii.xml"</code>.</p>
- <code><pre>public static var radiiLoader:RadiiDataHelper
- = new RadiiDataHelper( "xml/radii.xml" );</pre></code>
- <p>If you did not use code-completion, add the import for helper.RadiiDataHelper at this time. RadiiDataHelper is the external loader and already has the logic for loading the data.</p>
+
+```
+public static var radiiLoader:RadiiDataHelper
+ = new RadiiDataHelper( "xml/radii.xml" );
+```
+
+<p>If you did not use code-completion, add the import for helper.RadiiDataHelper at this time. RadiiDataHelper is the external loader and already has the logic for loading the data.</p>
<h3><br />Alter the array to use the external data</h3>
<p>Now that you are loading the radii data from an external source the <code>radii</code> variable no longer requires the static values. The <code>radii</code> variable must also be marked with <code>[DataPoints(loader="radiiLoader")] metadata</code>.</p>
</li>
<li>
<p>Modify the radii array so that it has <code>[DataPoints(loader="radiiLoader")]</code> metadata.</p>
- <code><pre>[DataPoints]
+
+```
+[DataPoints]
[ArrayElementType("Number")]
-public static var radii:Array = [ -5, 1,2,3,4,5,6,7,8,9,10 ];</pre></code>
- <p>Becomes:</p>
- <code><pre>[DataPoints(loader="radiiLoader")]
+public static var radii:Array = [ -5, 1,2,3,4,5,6,7,8,9,10 ];
+```
+
+<p>Becomes:</p>
+
+```
+[DataPoints(loader="radiiLoader")]
[ArrayElementType("Number")]
-public static var radii:Array;</pre></code>
- </li>
+public static var radii:Array;
+```
+
+</li>
<li>
<p>Save CircleTheory.as.</p>
<h3><br />Examing the loader class</h3>