| Class | Test::Unit::TestCase |
| In: |
lib/test/unit/testcase.rb
|
| Parent: | Object |
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.
You can run two hooks before/after a TestCase run.
Example:
class TestMyClass < Test::Unit::TestCase
class << self
def startup
...
end
def shutdown
...
end
end
def setup
...
end
def cleanup
...
end
def teardown
...
end
def test_my_method1
...
end
def test_my_method2
...
end
end
Here is a call order:
| method_name | [R] |
Describes a test.
The following example associates "register a normal user" description with "test_register" test.
description "register a normal user"
def test_register
...
end
Called after every test case runs. Can be used to tear down fixture information used in test case scope.
Here is an example test case:
class TestMyClass < Test::Unit::TestCase
class << self
def shutdown
...
end
end
def teardown
...
end
def test_my_class1
...
end
def test_my_class2
...
end
end
Here is a call order:
Note that you should not assume test order. Tests should be worked in any order.
Called before every test case runs. Can be used to set up fixture information used in test case scope.
Here is an example test case:
class TestMyClass < Test::Unit::TestCase
class << self
def startup
...
end
end
def setup
...
end
def test_my_class1
...
end
def test_my_class2
...
end
end
Here is a call order:
Note that you should not assume test order. Tests should be worked in any order.
Defines a test in declarative syntax or marks following method as a test method.
In declarative syntax usage, the following two test definitions are the almost same:
description "register user"
def test_register_user
...
end
test "register user" do
...
end
In test method mark usage, the "my_test_method" is treated as a test method:
test
def my_test_method
assert_equal("call me", ...)
end
Sets the current test order.
Here are the available order:
Called after every test method runs but the test method isn‘t marked as ‘passed’. Can be used to clean up and/or verify tested condition. e.g. Can be used to verify mock.
You can add additional cleanup tasks by the following code:
class TestMyClass < Test::Unit::TestCase
def cleanup
...
end
cleanup
def my_cleanup1
...
end
cleanup
def my_cleanup2
...
end
def test_my_class
...
end
end
Here is a call order:
Returns a description for the test. A description will be associated by Test::Unit::TestCase.test or Test::Unit::TestCase.description.
Returns a name for the test for no description test.
Runs the individual test method represented by this instance of the fixture, collecting statistics, failures and errors in result.
Called before every test method runs. Can be used to set up fixture information.
You can add additional setup tasks by the following code:
class TestMyClass < Test::Unit::TestCase
def setup
...
end
setup
def my_setup1
...
end
setup
def my_setup2
...
end
def test_my_class
...
end
end
Here is a call order:
Called after every test method runs. Can be used to tear down fixture information.
You can add additional teardown tasks by the following code:
class TestMyClass < Test::Unit::TestCase
def teardown
...
end
teardown
def my_teardown1
...
end
teardown
def my_teardown2
...
end
def test_my_class
...
end
end
Here is a call order: