Flex-flexunit-integration
提供:Dev Guides
Flex-FlexUnit統合
Flash Builder 4には、Flex開発サイクルでのFlexUnit統合に対する優れた組み込みサポートがあります。
テストケースクラスを作成する
Flash Builderのテストクラス作成ウィザードを使用して、テストケースクラスを作成できます。 この記事で説明するように、Flash Builderを使用すると、テストケースを簡単に実行できます。
Flash Builderを使用してテストケースクラスを作成するには、*ファイル>新規>テストケースクラス*をクリックします。 以下に示すように詳細を入力します。
Flash Builderは、次のTestClass1 ..をファイルとして作成します。
package com.finddevguides.client {
public class TestClass1 {
[Before]
public function setUp():void {}
[After]
public function tearDown():void {}
[BeforeClass]
public static function setUpBeforeClass():void {}
[AfterClass]
public static function tearDownAfterClass():void {}
}
}
FlexUnit統合の例
ここで、FlexアプリケーションでFlexUnit統合をテストする手順に従います-
Step | Description |
---|---|
1 | Create a project with a name HelloWorld under a package com.finddevguides.client as explained in the Flex - Create Application chapter. |
2 | Modify HelloWorld.mxml as explained below. Keep rest of the files unchanged. |
3 | Create TestClass1.as test case as described above and Modify TestClass1.as as explained below. |
4 | Compile and run the application to make sure business logic is working as per the requirements. |
以下は、変更されたファイル src/com.finddevguides/client/TestClass1.as の内容です。
package com.finddevguides.client {
import org.flexunit.asserts.assertEquals;
public class TestClass1 {
private var counter: int = 1;
[Before]
public function setUp():void {
//this code will run before every test case execution
}
[After]
public function tearDown():void {
//this code will run after every test case execution
}
[BeforeClass]
public static function setUpBeforeClass():void {
//this code will run once when test cases start execution
}
[AfterClass]
public static function tearDownAfterClass():void {
//this code will run once when test cases ends execution
}
[Test]
public function testCounter():void {
assertEquals(counter, 1);
}
}
}
以下は、変更されたmxmlファイル src/com.finddevguides/HelloWorld.mxml の内容です。
<?xml version = "1.0" encoding = "utf-8"?>
<s:Application xmlns:fx = "http://ns.adobe.com/mxml/2009"
xmlns:s = "library://ns.adobe.com/flex/spark"
xmlns:mx = "library://ns.adobe.com/flex/mx"
minWidth = "500" minHeight = "500">
</s:Application>
すべての変更が完了したら、link:/flex/flex_create_application [Flex-アプリケーションの作成]の章で行ったように、通常モードでコンパイルしてみましょう。
テストケースの実行
パッケージエクスプローラーでTestClass1を右クリックし、[実行]> [FlexUnitテスト]を選択します。 Flash Builderのテストウィンドウに次の出力が表示されます。
Flash Builderでは、ブラウザーにテスト結果も表示されます。