![]() |
C.1 Simplified Unit Testing |
option test on %test print 'We are in test mode' age = 15 %test age = 25 debug show ageLet's say there is an include file filled with testing code. You could conditionally compile and run that testing code by:
option test on tax_rate = 6.5/100 %test %include 'safe_unit_tests.spinc'Here is what safe_unit_tests.spinc looks like. Notice the use of the assert statement. You tell assert what is expected and it produces an exception if the assert fails:
// safe_unit_tests.spinc print 'Testing the tax_rate of '; tax_rate assert tax_rate > 0 and tax_rate <= 1.00, 'Tax rate is out of bounds' print 'Tax rate is fine'For clarity in your code, you can explicitly turn off test mode by:
option test offBy default, test mode is turned off.
Hide Description
|
|
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |