2009/06/11

FlexUnit 4 - Testメタデータ

前回の「FlexUnit 4 - 進化したJUnit4ライクな単体テストフレームワーク」に引き続き、「Major New Features of FlexUnit 4」をベースに話を進めていきます。

Major New Features of FlexUnit 4
http://opensource.adobe.com/wiki/display/flexunit/FlexUnit+4+feature+overview

1. Testメタデータ
FlexUnit 4では新たにTestメタデータが提供されていて、テストメソッドにマーカーとして付ける。
以前のバージョンまでは、テストケースはTestCaseクラスを継承したクラスとして作り、さらにテストメソッドにはtestMax, testMinのようにtestというprefixが必要だったが、FlexUnit 4から不要になった。

比較のため、FlexUnit 0.9、JUnit4、FlexUnit 4の簡単なサンプルテストケースを紹介する。
このケースでは、最大値max、最小値minを求める計算をテストしている。

FlexUnit 0.9
package net.air_life
{
import flexunit.framework.*;

public class SampleTest extends TestCase
{
public function testMax():void
{
assertEquals(100, Math.max(0, 100));
}

public function testMin():void
{
assertEquals(0, Math.min(0, 100));
}
}
}

JUnit4
package net.air_life;

import static org.junit.Assert.*;
import org.junit.*;

public class MathTest {
@Test
public void max() {
assertEquals(100, Math.max(0, 100));
}

@Test
public void min() {
assertEquals(0, Math.min(0, 100));
}
}


FlexUnit 4
package net.air_life
{
import org.flexunit.Assert;

public class MathTest
{
[Test]
public function max():void
{
Assert.assertEquals(100, Math.max(0, 100));
}

[Test]
public function min():void
{
Assert.assertEquals(0, Math.min(0, 100));
}
}
}

このように、FlexUnit 4からはTestCaseクラスの継承、prefix(test)が不要になりJUnit4に本当にそっくりになってきた。

次回に続く...

2. Before, Afterメタデータ
3. BeforeClass, AfterClassメタデータ
4. 例外ハンドリング
5. Ignoreメタデータ
6. async
7. Hamcrest
8. Suiteメタデータ
9. ユーザー定義メタデータパラメータ
10. Theory, Datapoints, Assumptionsメタデータ
11. RunWithメタデータ
12. アダプタ
13. ユーザーインターフェースファサード



FlexUnit 4 - 進化したJUnit4ライクな単体テストフレームワーク
http://blog.air-life.net/2009/06/flexunit-4-unit-testing-framework-for.html

1 件のコメント:

Unknown さんのコメント...

 ひっそりと続きを待ち望んでおります。
 FlexUnit4の記事は少ないですねー。