=encoding euc-jp =head1 NAME Test::Unit::TestSuite - ユニットテストフレームワークの基礎となるクラス =cut =head1 SYNOPSIS package MySuite; use base qw(Test::Unit::TestSuite); sub name { 'My very own test suite' } sub include_tests { qw(MySuite1 MySuite2 MyTestCase1 ...) } This is the easiest way of building suites; there are many more. Read on ... スイートを構築するための最も簡単な方法です。更なる情報が欲しいなら 読み続けてください。 =head1 DESCRIPTION This class provides the functionality for building test suites in several different ways. このクラスは様々な違った方法でテストスイートを構築するための 機能を提供します。 Any module can be a test suite runnable by the framework if it provides a C method which returns a C object, e.g. C を返す C メソッドを提供すれば、 フレームワークによってテストスイートは実行できるようになります。 use Test::Unit::TestSuite; # more code here ... sub suite { my $class = shift; # Create an empty suite. my $suite = Test::Unit::TestSuite->empty_new("A Test Suite"); # Add some tests to it via $suite->add_test() here return $suite; } This is useful if you want your test suite to be contained in the module it tests, for example. 例えば、テストを含んだモジュールのテストスイートが欲しいときに便利です。 Alternatively, you can have "standalone" test suites, which inherit directly from C, e.g.: また、C を直接継承した "standalone" テストスイートを 作ることもできます。例を挙げます。 package MySuite; use base qw(Test::Unit::TestSuite); sub new { my $class = shift; my $self = $class->SUPER::empty_new(); # Build your suite here return $self; } sub name { 'My very own test suite' } or if your C is going to do nothing more interesting than add tests from other suites and testcases via C, you can use the C method as shorthand: C 経由のテストケースやその他のスイートからテストを 追加すること以外に何もやりたくなければ C を使います。 C を使って短く書くこともできます。 package MySuite; use base qw(Test::Unit::TestSuite); sub name { 'My very own test suite' } sub include_tests { qw(MySuite1 MySuite2 MyTestCase1 ...) } This is the easiest way of building suites. これがスイートを構築するための最も簡単な方法です。 =head1 CONSTRUCTORS =head2 empty_new ([NAME]) my $suite = Test::Unit::TestSuite->empty_new('my suite name'); Creates a fresh suite with no tests. テスト無しに新しいスイートを生成します。 =cut =head2 new ([ CLASSNAME | TEST ]) If a test suite is provided as the argument, it merely returns that suite. If a test case is provided, it extracts all test case methods from the test case (see L) into a new test suite. 引数としてテストスイートを与えたならば、ただスイートだけを返します。 テストケースを与えたならば、新しいテストスイートの中に (L の)テストケースメソッド全てを 抽出します。 If the class this method is being run in has an C method which returns an array of class names, it will also automatically add the tests from those classes into the newly constructed suite object. このメソッドを実行するクラスがクラス名の配列を返す C メソッドを持つならば、それらのクラスから新しいコンストラクトスイート オブジェクトの中にテストを自動的に追加します。 =cut =head1 METHODS =cut =head2 name() Returns the suite's human-readable name. スイートの名前を人間にわかる表現で返します。 =cut =head2 names() Returns an arrayref of the names of all tests in the suite. スイートの中の全てのテストの名前を配列リファレンスで返します。 =cut =head2 list (SHOW_TESTCASES) Produces a human-readable indented lists of the suite and the subsuites it contains. If the first parameter is true, also lists any testcases contained in the suite and its subsuites. スイートやそれを含むサブスイートのリストを人間が読み易いようにインデント します。最初のパラメータが真の場合、スイートやそのサブスイートに 含まれているあらゆるテストケースもリストにします。 =cut =head2 add_test (TEST_CLASSNAME | TEST_OBJECT) You can add a test object to a suite with this method, by passing either its classname, or the object itself as the argument. 引数としてそのクラス名かオブジェクト自体を渡せば、このメソッドを 持ったスイートへテストオブジェクトを追加します。 Of course, there are many ways of getting the object too ... もちろん、オブジェクトを得る方法はたくさんあります。 # Get and add an existing suite. # 存在するスイートを追加、取得します。 $suite->add_test('MySuite1'); # This is exactly equivalent: # この方法でも全く等価です。 $suite->add_test(Test::Unit::TestSuite->new('MySuite1')); # So is this, provided MySuite1 inherits from Test::Unit::TestSuite. # Test::Unit::TestSuite を継承した MySuite1 を与えます。 use MySuite1; $suite->add_test(MySuite1->new()); # Extract yet another suite by way of suite() method and add it to # $suite. # suite() 経由でまた別のスイートを抽出し、$suite に追加します。 use MySuite2; $suite->add_test(MySuite2->suite()); # Extract test case methods from MyModule::TestCase into a # new suite and add it to $suite. # 新しいスイートへ MyModule::TestCase からテストケースメソッドを抽出し、 # $suite に追加します。 $suite->add_test(Test::Unit::TestSuite->new('MyModule::TestCase')); =cut =head1 AUTHOR Framework JUnit authored by Kent Beck and Erich Gamma. Ported from Java to Perl by Christian Lemburg. Copyright (c) 2000 Christian Lemburg, Elemburg@acm.orgE. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Thanks go to the other PerlUnit framework people: Brian Ewins, Cayte Lindner, J.E. Fritz, Zhon Johansen. =head1 SEE ALSO =over 4 =item * L =item * L =item * For further examples, take a look at the framework self test collection (t::tlib::AllTests). 更なる例は、このフレームワーク自体のテスト(t::tlib::AllTests)を 見てください。 =back =cut