skip example¶
require 'test/unit'
require 'rbconfig'
include Config
# tc_some_test.rb
class TC_SomeTest < Test::Unit::TestCase
def setup
@obj = MyUnixClass.new
end
# Skip this test on MS Windows
def test_something
skip('MS Windows'){ CONFIG['host_os'] =~ /mswin/i }
assert_equal(5, @obj.test)
end
def test_something_else
assert_equal(true, @obj.foo?)
assert_equal(true, @obj.bar?)
end
def test_yet_something_else
assert_equal(7, @obj.whatever)
end
def teardown
@obj = nil
end
end
If this test case is run on MS Windows the output will look something like this:
Loaded suite tc_some_test Started .S. Finished in 0.0 seconds. 3 tests, 3 assertions, 0 failures, 0 errors, 1 skipped
There were three tests, but one test was skipped. The three assertions that ran were from the test_something_else and test_yet_something_else methods.
The 'S' in the runner output is a visual indicator that a test was skipped.