Monthly Archives: September 2012

How do I get started with TDD ?

When one of our team is trying Test Driven Development, we were looking at ways to get us started. Because TDD is totally opposite to how we are used to doing things, when looking for some inspiration, my manager gave me this http://nsbrief.com/40-graham-lee

This interview with Graham Lee goes on for 1 hour 20mins, but it not just pure TDD, it has also about Objective C,etc. So , i thought why not extract TDD specific part plus some of my input, so not everyone has to sit and listen for so long.

TDD – There is no code to test, why are you writing the test in the first place?

it helps to make sure you understand the problem you are trying to solve

it is a useful design tool. Your unit test will be a blue print for the class you are going to write

You will start to feel like you are coding backwards

It forces you to think about how you are going to use this class in the first place before you write a line of code, its a different process

How to get into TDD ?

Its really practice that helps you to understand

‘It was taught as a training course, it didn’t make any sense , why i was testing code’ – more of hands on instead of training helps you get up to speed.

Try to apply on few projects, first it will slow you down, it will be frustrating because you will be thinking in a different way than you used to.

After you written some classes in test driven way, it starts to become more natural

Best way to start TDD is with a bug fix, when you finish, you got your regression test in place as well

Writing unit test before code

Write notes on empty unit tests based on the requirement,  write like a To-Do list inside the unit test class and it really comes down to fill in the blanks – turning each to-do items to java statements

Always have them fail, never make them just pass by default or skip

Don’t give up until you finish all of the tests

Starts to think about problems,  how do you prove that you have solved this problem?, how do you write a test that demonstrate that you have completed this task?

You unit test could cover only 80% of you class and still pass, how do you prove that it covers 100% ? Creating the above to-do list will be helpful.

Why TDD instead of BDD ?

TDD – you only write code that you only need

You could still write test/automation to cover this scenarios that you are going to write, so why still we need TDD ?

programmers are naturally lazy, while we can write cases for thing we don’t actually need to cover, its becomes useless

you don’t have to restrict TDD to unit test, using cucumber you can make it appear as TDD

To some level they have the same kind of philosophy

Committing code ?

Should you commit all your passing test or wait until it becomes green

With CD, only option is to check-in unit test which passes, otherwise it will break the build.

In case of more than one person working on related code, and one dependent on another, he/she may have to unshelve others’ code to test his/her code.

thats all folks!

Advertisements