Cactusを使ったEJB のテスト Howto/EJB Testing with Cactus Howto

Last update : July 6 2002
Doc for : v1.3

Cactusについて
  • Cactus とは
  • ニュース
  • 変更履歴
  • 特徴/開発状況
  • 目標
  • ロードマップ/ToDo
  • 協力者
  • 協力者募集
  • Cactus ユーザ
  • テスト済環境 ...
  • ライセンス


  • ダウンロード
  • ダウンロード


  • ドキュメント
  • Cactus の仕組み
  • さぁ始めよう
  • モック対コンテナ
  • Javadocs
  • └Javadocs
  • よくある質問


  • Howto ガイド
  • クラスパス Howto
  • 設定 Howto
  • アップグレードHowto
  • テストケース Howto
  • セキュリティHowto
  • Ant Howto
  • HttpUnit Howto
  • サンプル Howto
  • EJB Howto
  • IDE Howto
  • JUnitEE Howto


  • サポート
  • Bug DB
  • メーリングリスト


  • その他
  • 名前の由来
  • ロゴコンテスト
  • 参考文献
  • アクセス状況
  • └WebAlizer


  • 開発者向け
  • CVS
  • コード規約
  • ビルドの結果


  • はじめに/Introduction

    This document explains how to unit test EJBs with Cactus. It is divided in 2 parts :

    このドキュメントでは、Cactus を使って EJB を単体テストする方法について説明します。 ドキュメントは 2 つの節に分かれています :

    Note EJB unit testing works with Cactus 1.0 or later.

    Note EJB 単体テストは Cactus 1.0 以上で動作します。


    一般的な概念/General Concepts

    EJB をテストするのに何故 Cactus を使うのか/Why use Cactus for testing EJBs ?

    You might be wondering why you would use Cactus to unit test your EJBs whereas you could use standard JUnit test cases. Indeed, you could write a standard JUnit test case and view your code as client side code for the EJB to test ... There are actually a few reasons to choose Cactus instead :

    標準の JUnit テストケースが使えるのに、 何故、自分の EJB を単体テストするのに Cactus を使うのか不思議に思われるかもしれません。 実際、標準の JUnit テストケースを記述して、 自分のコードをテストする EJB のためのクライアント用コードとして見ればよいでしょう。 代わりに Cactus を選ぶ理由が本当に 2、3 あるのです。

    • If you are using local interfaces (EJB 2.0), then your beans cannot be called remotely (i.e. the caller need to be in the same jvm). However, as all Cactus redirectors run on the server side, you can unit test your local interfaces with Cactus.
    • ローカルインタフェース(EJB 2.0)を使っている場合、 あなたの bean はリモートで呼び出せません。 (即ち、呼び出し側は同じ JVM に無ければならないのです。) しかしながら、全ての Cactus リダイレクタがサーバ側で実行されているならば、 Cactus を使ってローカルインタフェースを単体テストできるのです。
    • Very often the production code that will call the EJBs is server side code (Servlets, JSPs, Tag libs or Filters). This means that if you run the tests from a standard JUnit test case, your tests will run in a different execution environment than the production one, which can lead to different test results,
    • EJB を呼び出す製品のコードは、大抵サーバ側のコードです (Servlets, JSPs, Tag libs or Filters)。 これは、 標準の JUnit テストケースからテストを実行した場合、 テストは製品の物とは異なるテスト実行環境で実行され、 異なるテスト結果を導くことになることを意味します。
    • An application using EJBs very often includes a front end part which is in almost all cases a web application (i.e. using Servlets, JSP, Tag libs or Filters). It means that you would also need a framework for unit testing these components. Cactus is providing a comprehensive and consistent framework for testing all server side components. This is a compelling enough reason to use it !
    • EJB を使ったアプリケーションは、通常、 ほとんど全てのケースで、 ウェブアプリケーションであるようなフロントエンドを持っています。 これは、これらのコンポーネントを単体テストするためのフレームワークも必要になってくることを意味します。 Cactus は全てのサーバ側コンポーネントをテストするための包括的で堅実なフレームワークを提供しています。 これは、Cactus を使う拒みきれない充分な理由です。
    • Cactus provides automated Ant tasks to automatically start your EJB server, run the tests and stop it, thus automating your entire test process and making it easy to implement continuous build and continuous integration of your J2EE project.
    • Cactus は、 自動的に EJB サーバーを起動し、 テスト実行し、停止する自動化された Ant タスクを提供するので、 従って、テスト全体の手続きを自動化し、 J2EE プロジェクトの継続的なビルドの実装、および、 継続的なインテグレーションを簡単にするのです。

    手順/The process

    You can unit test your EJBs from any of Cactus redirectors : ServletTestCase, JspTestCase or FilterTestCase.

    ServletTestCaseJspTestCaseFilterTestCase 等、 どの Cactus リダイレクタからでも EJB の単体テストができます :

    This means that you would write a test case class that extends any of Cactus redirectors, get a home reference to your EJB, create an instance of it, call the method to test and perform asserts on the result.

    これは、 いずれかの Cactus リダイレクタを拡張したテストケースクラスを記述し、 EJB のホームリファレンスを得て、 そのインスタンスを生成し、 テストのためにメソッドを呼び出し、 結果に対してアサーションを実行します。

    It is that simple ! What is slightly more complex is the deployment of your EJBs to your EJB container but you should be familiar with this, right ?

    これはとても単純です。 多少複雑なことは、 自分の EJB を EJB コンテナに配備することですが、 これについては、とっくに知ってますよね。



    J2EE RI チュートリアル/J2EE RI Tutorial

    This J2EE RI tutorial is a step by step guide for writing Cactus EJB unit test for the Sun J2EE RI server.

    この J2EE RI チュートリアル は、Sun J2EE RI サーバー上で Cactus EJB 単体テストを記述するための、 初心者向けガイドです。




    Copyright © 2000-2002 The Apache Software Foundation. All Rights Reserved.