If you're given a task to be done in TDD, it's not usually whether you can resolve that problem. It's about testing whether you have the right mindset, process and coding style that TDD suggests:
- Do you really understand the TDD Process? Benefits? Disadvantages?
- Can you explain the TDD process?
- Do you follow the TDD process in practice if you say you understand? e.g. if add something to the production code for which you don't have test, you have failed TDD!
- Will you choose a small behaviour from the spec before writing any test or you think big and complex?!
- Will you write a very small test method before writing any production code? how committed are you to this mindset?
- Will you run all your tests after writing your test, after making a production change?
- Would your test method names follow a proper pattern?
- Will you make sure that you write the minimum amount of implementation code so that only one test passes? You may be able to write all the solution quickly but that’s not TDD! only write the minimum possible amount of code to pass your failed test. remember code quality is not important at this stage. Will you write the minimum possible amount of code for your tests and production code? or you make things complicated or write production code without having the test for it.
- Will you refactor your production code after your tests passed?
When should you run all tests according to TDD?
- After adding a test
- After each change to the production code to pass 1 test
- After each refactoring
How to fail TDD Process?!
A TDD practical test in an interview often means that you should rigidly demonstrate TDD:
- If you write 1 single line of production code before you have a failing test for it, you have failed TDD!
- If you don't run all your tests after you made a production code change, you have failed TDD!
- If what you write is not minimized and focused only to pass your failed test and covers more scenarios than what tests you have, you have failed TDD!
- If you don't run all your tests after your refactoring, you have failed TDD!