Unit testing is without any doubts one of the most effective ways to detect bugs early and to write more reliable and maintainable code. Unit testing is therefore fully integrated in Obix and easy to use.
To check whether factory
fa_contribution works as it is supposed to work we should now write a unit test. Proceed as follows:
fa_contribution.osc which you created in the previous chapter
Insert the following test script just before the last line of code (just before the last
test script // create a 'contribution' object and assign it to constant 'c' const contribution c = fa_contribution.create ( & identifier = 123 & first_name = "Albert" & last_name = "Newton" & random_number = 5 & date_time = fa_local_date_time.create ( "2011-08-27T16:16:30"~ ) ) // verify all attributes verify c.identifier =v 123 verify c.first_name =v "Albert" verify c.last_name =v "Newton" verify c.random_number =v 5 verify c.date_time.to_string =v "2011-08-27T16:16:30" // verify the value returned by the 'to_string' command verify c.to_string =v "Albert Newton contributed '5' on 2011-08-27T16:16:30" end end
Compile and build the project again (by executing the
compile_and_build system file).
Now execute the unit test by executing the
run_tests system file which is located in your projects root directory (i.e.
run_tests.sh on Linux systems and
run_tests.bat on Windows systems).
If everything went fine the following is displayed on your system console:
Running unit tests in random_arcs testing random_arcs.contribution.fa_contribution 1 object has been tested. BRAVO AND CONGRATULATIONS! All tests passed without errors.