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 /= Void

>     assert_equal (a_tag: STRING; expected, actual: ANY)
>             -- Assert that equal (expected, actual).
>         require
>             a_tag_not_void: a_tag /= Void

>     assert_not_equal (a_tag: STRING; expected, actual: ANY)
>             -- Assert that not equal (expected, actual).
>         require
>             a_tag_not_void: a_tag /= Void

>     assert_same (a_tag: STRING; expected, actual: ANY)
>             -- Assert that expected = actual.
>         require
>             a_tag_not_void: a_tag /= Void

>     assert_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 /= Void

>     assert_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 /= Void

>     assert_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

>     feature -- Access

>         db: DATABASE
>                 -- Database to be tested

>     feature -- Setting

>         set_up is
>                 -- Connect to the database.
>             do
>                 create db.make
>                 db.connect
>             end

>         tear_down is
>                 -- Disconnect from the database.
>             do
>                 db.disconnect
>                 db := Void
>             end

>     feature -- Test

>         test_connection is
>                 -- Test database connection.
>             do
>                 assert ("db_not_void", db /= Void)
>                 assert ("db_connected", db.is_connected)
>             end

>         test_insertion is
>                 -- 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