すべてのテスト ケースを自動的に実行する代わりに、Ruby テスト/ユニット フレームワークで単一のテストを実行する方法はありますか。Rake を使用してそれを達成できることはわかっていますが、現時点では rake に切り替える準備ができていません。
ruby unit_test.rb #this will run all the test case
ruby unit_test.rb test1 #this will only run test1
すべてのテスト ケースを自動的に実行する代わりに、Ruby テスト/ユニット フレームワークで単一のテストを実行する方法はありますか。Rake を使用してそれを達成できることはわかっていますが、現時点では rake に切り替える準備ができていません。
ruby unit_test.rb #this will run all the test case
ruby unit_test.rb test1 #this will only run test1
コマンドラインで -n オプションを渡すと、単一のテストを実行できます。
ruby my_test.rb -n test_my_method
ここで、'test_my_method' は実行したいテスト メソッドの名前です。
非シェルソリューションを探す場合は、TestSuiteを定義できます。
例:
gem 'test-unit'
require 'test/unit'
require 'test/unit/ui/console/testrunner'
#~ require './demo' #Load the TestCases
# >>>>>>>>>>This is your test file demo.rb
class MyTest < Test::Unit::TestCase
def test_1()
assert_equal( 2, 1+1)
assert_equal( 2, 4/2)
assert_equal( 1, 3/2)
assert_equal( 1.5, 3/2.0)
end
end
# >>>>>>>>>>End of your test file
#create a new empty TestSuite, giving it a name
my_tests = Test::Unit::TestSuite.new("My Special Tests")
my_tests << MyTest.new('test_1')#calls MyTest#test_1
#run the suite
Test::Unit::UI::Console::TestRunner.run(my_tests)
実際には、テストクラスMyTestは元のテストファイルからロードされます。