Testing for Developers, necessary evil (developers/managers read this)

I have always wondered why developers fail to test their own code. It believe its a upbringing issue. If you have worked with people who care a lot about product quality, and value the fact that defects must be found early, you will write and plan unit testing into your development effort. Basically if you have spent time with talented folks you will do what it takes to get your code/design and data model right. You will understand the difference between throwing exceptions and printing error messages on screens. Also the ability to debug your app later will be on your mind.

Also seems like developers get the attitude from their seniors/teachers, who imply that Testing is for idiots, and the fact that they strongly believe that they are the only chosen ones who can do development. Infact I can be sure that developers who dont believe in testing their own code, spend countless hours mocking testers.

Now you can say that the system is to blame. Managers dont care about unit test cases, customers only care about their tests working, ultimately the business managers who care only about “time to market”. Infact so strong is the communication from top, is “time to market” is the only important criteria. Quality is recognized only if “time to market”, estimates and dates are maintained. And every person who had delivered a project knows that “time to market” never takes a hit, its the quality.

To clean up the system it takes someone to start. Developer is just as good as anyone to start.

I wont spend time convincing developers to unit test their code, or to write test cases. But I will spend time to help developers who are convinced about unit testing and guide them thru their challenges.

Challenge No 1 : What to test ?
Every class needs to be tested. A class is testable if you have simple small classes that do just the job they are suppose to do. Keep your classes simple and hence testable.

Challenge No 2 : When to test ?
When you have completed coding of your class. And all methods have clear inputs and outputs.

Challenge No 3 : I am stuck, just cant think.
First get your hands off your computer. Take a pen and pencil and start putting down mind maps, input scenarios, what ever help you think.. THINK!!!! Just collect your thoughts. Personally I use the white board. I put down tables, flow charts, just to collect my thoughts..

Challenge No 4 : What test cases to write
Here you need to refer to the basics of software engineering. Unit test cases is positive tests, negative tests and boundary conditions. Our mind can get easily confused. So lets take this step by step. Start simple, positive test cases. Then negative and finally boundary. If you are as crazy as I am, also do “equivalence partitioning” for data sets that is beyond testing.

Challenge No 5 : I cant think!!!
Yes this is a reality people, developers put in soo much of their analytical thinking while coding, that thinking testing (which is a lateral and destructive thought, is a pain). Creative Thinking uses up the entire brain. Drink water, lots of it. The brain needs oxygen to think, and water is the only way the brain gets its needed oxygen. Take a walk with a pencil in your hand. Just relax and collect your thoughts.

Challenge No 6 : Im still stuck!!
Reply to this blog, lets discuss. You need a mentor and someone to bang your head against, a sound board. I can be that for you. reply.. lets talk it out..

Finally I leave you with this thought.
DO A KICK ASS JOB, not just a job.. “Just Coding” is for idiots.. Its the real men (or women for that matter) who can write test cases..

(This blog helped me gather my thoughts http://stackoverflow.com/questions/83147/whats-wrong-with-foreign-keys, especially comment by Ed Lucas)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s