Testing your code!
In Computer science it is very important to test your code to see it works with every test cases, otherwise when your client runs your code, if it doesn't work with a certain test case, you may get in trouble!
The testing part may be time consuming, but the thing is you can learn if there is a mistake that you have made and improve your code by changing somethings about your code.
before writing a function, I plan out my code, to see what it will do and plan out the certain arguments the function will take. This way I am sure of what test cases I have to do and I'm sure of the arguments that are invalid to this function.
when certain test cases do not pass i have to go back to the code and fix those mistakes. Finding the mistake is the easy part, improving the code is the hard part. This takes time for me, BUT i learn a lot from my mistakes.
In order to make test cases for your code, do the following:
1. Plan out your code, see what the outcome of your code will be.
2. Plan out what the code is required to do and based on that plan out some test cases.
3. Doing every single test case is very time consuming, so divide up those test cases into parts. These parts should contain smiliest test cases so you can pick the MOST important case in each of those parts and test them.
4. Once you're done with the parts write your code and test the most important test cases so you're sure of what the code can do!
Testing allows for improvement in the code, and if your code works with every input that a user can give, you have designed the perfect code (in my view)!
No comments:
Post a Comment