Hello Sundar
Yes I agree with you. TDD is a suggestion and not a strict rule. Rules are great for beginners, but experts know when to bend or break the rules.
I have seen companies who think that TDD is the only way forward, often following it in a religious manner without truly understanding its goals.
I think that both ways are applicable.
Sometimes I write the code first and then the tests if it makes sense. Sometimes I write multiple tests that succeed directly after the first run.
A particular area where I think TDD is not that helpful, is when I am prototyping something. There are no clear specs so it is very hard to write
unit tests if the details are blurry.
Finally, while TDD helps you write testable code, a
Java guru can write testable code (i.e. with good design, SOLID principles, IOC etc) without actually writing any unit tests first.
Not all people can do it, but there are some who can (and no, I do not claim I am that good)
I think TDD has great value in big teams where team members have uneven Java knowledge. But blindly assuming that TDD is always the solution is obviously wrong.
So yes, both ways are applicable in different circumstances exactly as you say.
Kostis