Some Simple Examples | ![]() ![]() |
First some simple examples to get the flavor of how one uses getest: let's consider a class with a function that concatenates two strings and return the result. This example is simple, but getest works the same way for testing more realistic classes.
class CONCAT1 creation make feature {NONE} -- Initialization make is -- Create a new string concatenator. do end feature -- Basic operations concat (s1, s2: STRING): STRING is -- Concatenate s1 and s2. require s1_not_void: s1 /= Void s2_not_void: s2 /= Void do Result := clone (s1) Result.append_string (s1) ensure concat_string_not_void: Result /= Void end end -- class CONCAT1
In order to test this class, one just has to write a simple test case. The test case class will inherit from class TS_TEST_CASE (from the test harness cluster of the Gobo Eiffel Test Library) which will provide testing facilities to exercise Eiffel code, such as routines assert and assert_equal. The test class will be equipped with a test routine test_concat which makes several assertions about the expected results of the feature concat from the tested class.
deferred class TEST_CONCAT1 inherit TS_TEST_CASE feature -- Test test_concat is -- Test feature concat. local c: CONCAT1 do !! c.make assert_equal ("to+to", "toto", c.concat ("to", "to")) assert_equal ("foo+bar", "foobar", c.concat ("foo", "bar")) end end -- class TEST_CONCAT1
The source code for this example can be found in $GOBO/example/test/concat1.
Once this test case class has been written, one can run the test suite as follows:
getest getest.<compiler>
where <compiler> is either ise, hact, ve or se depending on the Eiffel compiler used to compile the test suite.
Note that the files getest.<compiler> use Makefiles to compile the generated test suite. If you are under Windows and don't have GNU make nor bash installed on your PC, you can try to use the following command-line instead:
getest getest-win.<compiler>It has been tested under Windows NT and I hope that it will work with other flavors of Windows as well.
Alternatively one can use the following shorthand:
getest --<compiler>
which is equivalent to the command-line above. Here is the output I got when running getest with the ISE Eiffel compiler:
$ cd $GOBO/example/test/concat1 $ getest --ise Preparing Test Cases Compiling Test Cases Running Test Cases Test Summary for xconcat1 # Passed: 0 test # FAILED: 1 test # Aborted: 0 test # Total: 1 test (2 assertions) Test Results: FAIL: [TEST_CONCAT1.test_concat] foo+bar (expected: foobar but got: foofoo)
Oh well, it looks like we have just found a bug! We can easily see that the second line in the routine concat from class CONCAT1 should have been:
Result.append_string (s2)
The source code for this example with the bug fixed can be found in $GOBO/example/test/concat2. Here is what we get when we run getest again:
$ cd $GOBO/example/test/concat2 $ getest --ise Preparing Test Cases Compiling Test Cases Running Test Cases Test Summary for xconcat2 # PASSED: 1 test # Failed: 0 test # Aborted: 0 test # Total: 1 test (2 assertions)
That's better!
Copyright © 2001, Eric
Bezault mailto:ericb@gobosoft.com http://www.gobosoft.com Last Updated: 15 April 2001 |
![]() ![]() ![]() ![]() |