SSブログ

主要なテストフレームワークの比較 [Test]

主要なテストフレームワークの比較(http://www.theserverside.com/articles/content/TestFrameworkComparison/article.html)

JUnit4.0の話題もちらほら聞こえる今日この頃です。記事を拝見させて頂き、少し纏めてみます。

全体的な所感

JUnit4.0, JTiger, TestNG、それぞれアプローチや細かい点に関しては異なる点もありますが、GOALは同じ方向であるように感じました。JUnitの制約から解放し、JDK1.5の機能(特にアノテーション)を利用した機能拡張が主な特徴であるように見受けられます。具体的には、いずれのテストフレームワークも以下の機能を実現しています。JUnit4.0の開発も開始されましたし、今後益々の発展を遂げてくれるかと思います。いずれのゴールに向かおうとも、我々開発者のテストに力を貸してくれるものと期待しています。

  • annotationの導入
  • クラス構造の制約から解放:クラスjunit.framework.TestCaseを継承する必要はない。
  • メソッド名の制約から解放:テストメソッド名は"test"から始まる文字列でなくとも構わない。"setUp","tearDown"というメソッド名の縛りも不要になる。
  • 特定のテストを無視させることができるようになる。
  • テストケースのカテゴライズ
  • static assertion method の導入(TestCaseクラスを継承する必要はない)

詳細は以下に纏めてみます。

比較対象のテストフレームワーク

JTiger

JDK1.5の機能に影響を受けて開発されたアノテーションに基づくテストフレームワーク

特徴

  • annotationやstatic imports
    ※static imports は必ずしも必要ではない。可読性を向上させるため。
  • テスト実行するために外部の設定ファイルを必要としない。
  • JUnitのように ant による実行が可能。

annotation

Annotation

Description

@Test

defines a test case to be executed

@Category

Specifies the category (or categories) to which the test belongs. Can be attached to a method or class declaration

@Ignore

Tells JTiger to ignore the test

@SetUp

Defines the set up method to be used for the tests

@TearDown

Defines the tear down method to be used for the tests

@ExpectException

Tells JTiger to expect exceptions to be thrown from the test. This takes the class definition of the expected exception with an optional boolean to allow subclasses or not. This removes the need for things like this:

	  try {
	shouldFail();
	fail();
} catch (SomeException e) {
	// success
}

@Repeat

Tell JTiger to repeat the test n times. Each run will have a distinct result and if n is less than 0, then 1 is used for n.

@Fixture

Used to document the fixture class with more useful names and descriptions.

assertion

  • JTiger は多くのassertion機能を提供します。詳細は以下のパッケージをご覧ください。(pacakge org.jtiger.assertion)

Test Results

  • JTigerのテスト結果には、以下の6つの異なる種類があります。 
    " Success ," " Ignored (Annotated), " " Ignored (Cannot Invoke), "   " Failure (Set Up), " " Failure, " " Failure (Tear Down) ." " Success "
  • test method の結果は void 以外も返却可能となります。void以外を返却する場合、返却されたオブジェクトに対してtoString()された文字列が出力されます。

 ■TestNG

JTigerと非常によく似た機能を実現しています。

  • テストケースのカテゴライズに関して
    the lack of @Category that JTiger uses. TestNG, instead, defines groups in the @Test annotation.
    TestNG also supports groups of groups with the following syntax: @Test(groups = {"group1", "group2"}).
  • テストケースの有効化・無効化
    Notice, also, the enabled = false. This provides the same functionality the same as the @Ignore JTiger provides.
     However, one big difference is that disabled tests will not be displayed in the report so that any disabled tests run the risk of getting lost. 
  • テストケースの適用範囲の制御
    @Test can be applied to methods as well as classes. When applied to the class, all public methods on the class are considered to be test cases. 
  • 繰り返し実行
    Like JTiger, TestNG tests can be repeated with @repeat(invocationCount=10).
  • テストに対する依存関係の定義
    TestNG also has the idea of dependencies on tests.
     The syntax for these dependencies is @Test(dependsOnMethods={"method1, method2"}) and @Test(dependsOnGroups={"group1, init.*"}).
     If these dependencies fail, the dependent methods are marked as skipped.
     This reduces the number of failures seen on the reports due to upstream failures and helps to highlight the actual error. 
  • テストケースに対するパラメータの受け渡しに関して
    Unlike JUnit and JTiger, TestNG methods can take parameters.
     @Parameters({"param1", "param2"}) defines the parameters param1 and param2.
     Values for these parameters are defined in the XML configuration file we'll see in a later section. 
  • 設定
    Using @Configuration, a developer can specify exactly when a method executes during a test run

■JUnit4

the goal of JUnit 4 is to "encourage more developers to write tests by simplifying JUnit."

主な特徴

  • IDE integration improvements
  • move to static assert methods like JTiger and TestNG use.
  • move to an annotation  based system.
    Set up and tear down will be handled with @Before and @After
    Shared set up is handled with @BeforeClass and @AfterClass
    @Ignore like JTiger
  • Test methods in JUnit 4 will no longer be required to start with test
  • The @Test annotation will support expected exceptions.(e.g. @Test(expected=NullPointerException.class))
  • JUnit 4 will introduce test ordering and prioritization as well as categorization and filtering.
  • JUnit 4 will also provide "forward compatibility" for current test runners 
  • a new assert: assertEquals(Object[], Object[]) as well as support Java's assert and AssertionError 
  • remove the distinction between failures and errors. 
  • a new package structure: org.junit . 
  • native logging support

Here is the list of available annotations provided by TestNG:

Annotation

Description

@Test

defines a test case to be executed

@Configuration

Configuration information for a TestNG class. Provides facilities for grouping and parameters.

@ExpectedExceptions

Like the JTiger annotation, tells TestNG to expect certain exceptions. Takes an array of class definitions.

@Factory

Factory annotation

 References


nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:パソコン・インターネット

nice! 0

コメント 0

コメントを書く

お名前:[必須]
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。