Reputation: 46287
How do you effectively test code that you wrote? I find that it is very hard to tiger test code that I have written for my site because part of me feels that I don't want to find bugs in my code because that shows I'm not perfect. (Even writing that I might not be perfect bother me a little bit.)
I believe in unit testing, but lately I've become a bit of a gunslinger and have been deploying lots of code to production from the hip (which isn't always bad for a new web startup, but often is.)
I've been bitten in the last few weeks by serious bugs that have gotten by my own testing. I have a partner who I push to black box test my own code, but due to my knowledge of the implementation details I really should be the best person to test the weak points of the code using white box testing.
So what methods and tools are useful to help you test code you have written yourself?
Upvotes: 3
Views: 629
Reputation: 24049
Upvotes: 0
Reputation: 72870
OK, here goes.
You are not perfect. I am not perfect. Nobody is perfect. So don't worry about exposing errors. The more you find yourself, rather than letting someone else find them for you, the closer to perfect you become.
Get into the habit of writing the tests before the code where you can. Define what the code should do with a meaningful set of tests, then code to get the tests passing. Then refactor - classic TDD.
If there are bugs, then immediately write a test that exposes the bug (i.e. that should pass, but fails because of the bug). Then get the test to pass, and you've fixed the bug.
Upvotes: 4
Reputation: 5874
To sum up:
TDD:
REGRESSION:
BUG FIX:
FUNCTIONAL TESTING:
Upvotes: 3
Reputation: 1577
First you should note all the possibilities of inputs, Then you have to test with all the possibilities. You can find our bugs and it will clear out lot of bugs. I am using this way only, so far i have no idea about the Tools
Upvotes: 0
Reputation: 15816
I've started to write unit tests before the code for all my personal projects bigger than 20 lines of code. It helps a lot.
Now I'm always surprised when people say that they hate unittests and TDD.
Upvotes: 1
Reputation: 21022
Writing the test before the code helps since I can think (without the bias set by the implementation in the mind) about what the behavior of the code should be in various conditions.
Upvotes: 4