Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test code easily?

I'm learning Java by reading "Head First Java" and by doing all the puzzles and excercies. In the book they recommend to write TestDrive classes to test the code and clases I've written, that's one really simple thing to do, but by doing this I think I can't fully test my code because I'm writing the test code knowing what I want to get, I don't know if it makes any sense, but I was wondering if there's any way of testing my code in a simple way that it tell's me what isn't working correctly. Thanks.

like image 552
Eduardo Rascon Avatar asked Aug 23 '10 21:08

Eduardo Rascon


1 Answers

that's right - you know what to expect, and write test cases to cover that knowledge. In many respects this is normal - you want to test the stuff you've written just so you know it works as you expect.

now, you need to take it to the next step: find a system where it will be working (ie integrate it with other bits n pieces of the complete puzzle) and see if it still works according to your assumptions and knowledge.

Then you need to give it to someone else to test for you - they will quickly find the bits that you never thought of.

Then you give it to a real user, and they not only find the things you and your tester never thought of, but they also find the things that were never thought of by the requirements analyst.

This is the way software works, and possibly the reason its never finished.

PS. One thing about your test code that does matter more than anything - once you've done it once and found it works as expected, you can add more stuff to your app and then run your test code again to make sure it still works as expected. This is called regression testing and I think its the only reason to write your own unit tests.

and: Dilbert's take on testing.

like image 147
gbjbaanb Avatar answered Oct 23 '22 10:10

gbjbaanb