Search code examples
unit-testingtestingtdd

When is Unit Testing done in the software development process?


I am aware of what Unit testing is but When I read about Test Driven Development, I got confused.

Is unit testing something you do ahead of the code-base following the test-first then develop process? or is it something you do mid or after development so you would just refactor some parts of the code-base(which is what I am doing in the project).

I would highly appreciate any enlightenment.


Solution

  • Test Driven Development means, that you write the unit tests before implementing the new feature. With this technique the developer will focus on writing only the code necessary to pass the test. Designs can often be cleaner and clearer than is achieved by other methods.

    But compared to normal unit testing, the developer needs a lot more experience to follow this technique. You need an understanding of the implementation including a vision of all layers involved or needed for this requirement, before starting to code (which is always the better way). Otherwise you will have to refactor a lot of code afterwards. Personally I like this approach, but as I said it requires more experience.

    If you are talking about unit testing only, this should always be part of the development process. Often you are writing your tests during development, sometimes when you think you are done. And if you need to refactoring an existing method, then it is also useful to write a test first to ensure you will not break existing functionality.