<is*********@gmail.comwrote in message
On Apr 12, 12:18 am, Ian Collins <ian-n...@hotmail.comwrote:
>Write decent unit tests before you write the function. Write the
function to pass the tests, nothing more.
Unit test. I heard of it. Is there any particular tool to do this?
Or I need write a file such as test_foo.c to test a function called
foo?
Generally you want the test code in a different file to the function code.
If the function has no dependencies and performs no IO then tests are
usually quite straightforwards. You need to write cases so that each
boundary is checked - try for zero, one, a normal number, maximum, and
maximum plus one. Each line of code should be executed at least once.
If the function has dependencies then the process is much more difficult. It
might depend on substantial portions of the program, so the test harness
becomes effectively the whole program. Input might be so difficult to set up
that the unit test becomes extremely difficult to devise. If the function
performs IO then of course you need the harware as well as part of your test
harness.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm