Assertions |
The test routines in the test case classes can use assertion features defined in class TS_ASSERTION_ROUTINES. Assertions routines have the prefix assert and when they are not true an error is reported to the test suite with the name of the test (i.e. feature name of the test routine) and the assertion tag. Assertion routines are inherited from class TS_TEST_CASE from the test harness cluster of the Gobo Eiffel Test Library. Following are the predefined assertion routines available so far:
assert (a_tag: STRING; a_condition: BOOLEAN) -- Assert a_condition. require a_tag_not_void: a_tag /= Voidassert_equal (a_tag: STRING; expected, actual: ANY) -- Assert that equal (expected, actual). require a_tag_not_void: a_tag /= Voidassert_not_equal (a_tag: STRING; expected, actual: ANY) -- Assert that not equal (expected, actual). require a_tag_not_void: a_tag /= Voidassert_same (a_tag: STRING; expected, actual: ANY) -- Assert that expected = actual. require a_tag_not_void: a_tag /= Voidassert_arrays_same (a_tag: STRING; expected, actual: ARRAY [ANY]) -- Assert that expected and actual have the same items -- in the same order (use '=' for item comparison). require a_tag_not_void: a_tag /= Void expected_not_void: expected /= Void actual_not_void: actual /= Voidassert_arrays_equal (a_tag: STRING; expected, actual: ARRAY [ANY]) -- Assert that expected and actual have the same items -- in the same order (use equal for item comparison). require a_tag_not_void: a_tag /= Void expected_not_void: expected /= Void actual_not_void: actual /= Voidassert_iarrays_same (a_tag: STRING; expected, actual: ARRAY [INTEGER]) -- Assert that expected and actual have the same items -- in the same order (use '=' for item comparison). require a_tag_not_void: a_tag /= Void expected_not_void: expected /= Void actual_not_void: actual /= Void
Test cases that require a common setup or tear down can redefine the features set_up and tear_down from TS_TEST_CASE to achieve that effect.
set_up -- Setup for a test. -- (Can be redefined in descendant classes.)tear_down -- Tear down after a test. -- (Can be redefined in descendant classes.)
Here is a simple example which tests a database class:
class TEST_DATABASE inherit TS_TEST_CASE redefine set_up, tear_down end create make_default feature -- Access db: DATABASE -- Database to be tested feature -- Setting set_up -- Connect to the database. do create db.make db.connect end tear_down -- Disconnect from the database. do db.disconnect db := Void end feature -- Test test_connection -- Test database connection. do assert ("db_not_void", db /= Void) assert ("db_connected", db.is_connected) end test_insertion -- Test insertion in database. do db.put ("gobo", "name") assert ("db_has_name", db.has ("name")) assert_equal ("inserted", "gobo", db.item ("name")) end end
Copyright © 2001-2008, Eric
Bezault mailto:ericb@gobosoft.com http://www.gobosoft.com Last Updated: 13 February 2008 |