Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > test/unit/autorunnerライブラリ > Test::Unit::AutoRunnerクラス > run

singleton method Test::Unit::AutoRunner.run

run(force_standalone = false, dir = '.', argv = ARGV) -> bool

テストを実行します。全てのテストが成功した場合、true を返します。そうでない場合は、 false を返します。

[PARAM] force_standalone:
true を与えると、dir 以下にある全てのテストを実 行します。false を与えた場合は既に読み込まれた ファイルの中からテストを探して実行します。テス トが読み込まれておらず、スクリプトを -e から実 行している場合は、dir 以下にある全てのテストを 実行します。デフォルトは false です。
[PARAM] dir:
force_standalone に true を与えた時に再帰的に探査するディレクトリ名を 与えます。デフォルトではカレントディレクトリを再帰的に探査します。
[PARAM] argv:
オプションを配列として与えます。解釈するオプションは先に 出てきたものと同じです。
-r, --runner=RUNNER              Use the given RUNNER.
                                 (c[onsole], f[ox], g[tk], g[tk]2, t[k])
-b, --basedir=DIR                Base directory of test suites.
-w, --workdir=DIR                Working directory to run tests.
-n, --name=NAME                  Runs tests matching NAME.
                                 (patterns may be used).
-t, --testcase=TESTCASE          Runs tests in TestCases matching TESTCASE.
                                 (patterns may be used).
-v, --verbose=[LEVEL]            Set the output level (default is verbose).
                                 (s[ilent], p[rogress], n[ormal], v[erbose])
    --                           Stop processing options so that the
                                 remaining options will be passed to the
                                 test.
-h, --help                       Display this help.

force_standalone に false を与えた時には次のオプションが追加されます。

-a, --add=TORUN                  Add TORUN to the list of things to run;
                                 can be a file or a directory.
-p, --pattern=PATTERN            Match files to collect against PATTERN.
-x, --exclude=PATTERN            Ignore files to collect against PATTERN.

require 'test/unit'
Test::Unit::AutoRunner.run(true, './', ['--runner=tk', '-v',
                                        '--exclude=/test_hoge.*\.rb\Z/i'])

argv にデフォルトのまま ARGV を渡しておけばコマンドラインからオプションを 指定できます。

require 'test/unit'
Test::Unit::AutoRunner.run(true, './')

と、runner.rb に書いておいて、コマンドラインから以下のように実行。

$ ruby runner.rb --runner=tk -v --exclude=/test_hoge.\*\\.rb\\Z/i
class Test::Unit::AutoRunner