Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > test/unit/testcaseライブラリ > Test::Unit::TestCaseクラス
クラスの継承リスト: Test::Unit::TestCase < Test::Unit::Assertions < Object < Kernel
テストの基本単位(あるいは「テスト本体」)を表すクラスです。 テストを行うメソッド(テストメソッド)は TestCase のサブクラスのインスタンスメソッド として定義されます。テストメソッドの名前は「test」で始まっていなければなりません。 逆に、「test」で始まっているメソッドは全てテストメソッドと見なされます。 各テストメソッドは、Test::Unit::TestCase.suite により Test::Unit::TestSuite オブジェクトへとひとつにまとめられます。
require 'test/unit'
require 'test/unit/ui/console/testrunner'
class TC_String < Test::Unit::TestCase
  def test_size
    assert_equal('abc'.size, 3)
  end
  def test_concat
    assert_raise(TypeError) do
      'abc' + 1
    end
  end
end
suite = TC_String.suite
Test::Unit::UI::Console::TestRunner.run(suite)
各 TestCase オブジェクトは、ひとつのテストメソッドに対応しています。テストが実行される時には、 テストメソッドの数だけ TestCase オブジェクトが生成されます。
Ties everything together. If you subclass and add your own test methods, it takes care of making them into tests and wrapping those tests into a suite. It also does the nitty-gritty of actually running an individual test and collecting its results into a Test::Unit::TestResult object.
| 定義 | 説明 | |
|---|---|---|
| 
  new(test_method_name) -> Test::Unit::TestCase
   | このメソッドをユーザが直接呼ぶことはありません。 | |
| 
  suite -> Test::Unit::TestSuite
   | 「test」ではじまるインスタンスメソッド全てに対して、それぞれに対応する TestCase オブジェクトを生成し、Test::Unit::TestSuite オブジェクト としてまとめたものを返します。 | |
| 定義 | 説明 | |
|---|---|---|
| 
  default_test -> ()
   | 常に失敗するテストです。 | |
| 
  method_name -> String
   | 自身に対応しているテストメソッドの名前を文字列で返します。 | |
| 
  name -> String
   | 自身に対応しているテストメソッドの名前を人間が読みやすい形式で返します。 | |
| 
  run(result) {|STARTED, name| ...}
   | このメソッドをユーザが直接呼ぶことはありません。 | |
| 
  setup -> ()
   | 各テストメソッドが呼ばれる前に必ず呼ばれます。 | |
| 
  size -> Integer
   | 常に 1 を返します。 | |
| 
  teardown -> ()
   | 各テストメソッドが呼ばれた後に必ず呼ばれます。 | |
| 定義 | 説明 | |
|---|---|---|
| 
  passed? -> bool
   | テストが成功したなら、true を返します。そうでないなら、false を返します。 Test::Unit::TestCase#teardown の中で使うことを意図されています。 テスト実行前に何を返すかは不定です。 | |
| 定義 | 説明 | |
|---|---|---|
| 
  PASSTHROUGH_EXCEPTIONS
   | Test::Unit::TestCase#run の実行時に rescue されない例外の一覧です。 | |
==
===
=~
__id__
__send__
_dump
class
clone
dclone
display
enum_for
eql?
equal?
extend
freeze
frozen?
hash
initialize
initialize_copy
inspect
instance_eval
instance_exec
instance_of?
instance_variable_defined?
instance_variable_get
instance_variable_set
instance_variables
is_a?
marshal_dump
marshal_load
method
method_missing
methods
nil?
pretty_inspect
pretty_print
pretty_print_cycle
pretty_print_inspect
pretty_print_instance_variables
private_methods
protected_methods
public_methods
remove_instance_variable
respond_to?
singleton_method_added
singleton_method_removed
singleton_method_undefined
singleton_methods
taint
tainted?
tap
to_a
to_ary
to_hash
to_int
to_io
to_proc
to_regexp
to_s
to_str
to_yaml
to_yaml_properties
to_yaml_style
untaint