Krista's Coding Corner

18.03.2012

Good code? -testing

Testing

Already said, good code has to work. Code might SEEM to work but it actually might work still wrongly. There is hardly any fool proof method to know that your code works as it should, but testing is the best tool of all. Test, test, test and test some more. You can never do enough testing.

Very usable tool, that is recommendable to use always, is to create multiple tests. Tests are small programs that try to use small parts of your code. They create some inputs, give it to certain part of code and check whether the output is correct. Tests only check input-output but because they check these inside of your program they are better than you just using the program. It is recommended to do the tests in advance, so that you don’t accidentally rewrite some misunderstanding or logic mistake. Also, every time you change something in your code (== do a new version), just run the test to know that nothing has got broken. Testing and debugging along the project/process gives you a lot less work in finding and fixing bugs than making everything in the end. That’s because mistakes can be mixed and added together making the code look more like spaghetti. Eating an elephant is also done by small parts, piece by piece, so why not testing? :)

blog comments powered by Disqus