Test Driven Developmen (TDD): What is it?

Recently my current company gave us a training on Test Driven Development (TDD). So today lets see what's TDD and how is it different from our everyday programming.
Test Driven Development is a way of developing programs where you focus on the testing aspect of the code and write unit tests and code together. How this is different from your day-to-day coding is that we write all code at once. Then we either before or after write the unit tests. Then we unit test the code. And then we find bugs and we fix them. In TDD, we write tests and then we write code to make that test pass. Once we have gone through all the tests, and written all the code to satisfy the tests, you are done.
So the advantages:
1. All code is unit tested.
2. Since we are writing only as much code to satisfy unit tests, code bloat should be less.
3. Since we are thinking only enough requirements for testing current tests, code should be cleaner.
4. Since we are coding, testing and debugging in one go, time should take lesser as compared to normal coding - which many TDD people call Debug-Later programming.
5. Since using TDD techniques of fake modules and mock function calls, we can test Legacy code, it's quality can improve when we continue Legacy code development using TDD. Legacy code is code developed in Debug-Later programming. This code many-a-times may not have complete requirement documents. Often the requirement spec is the behaviour of the code.
6. Unit testing can be automated and integrated in CI/CD.
7. Automating unit tests allows regressions to be detected much faster.
8. Since unit tests are themselves run as an application, we can have programmatic generated report, which avoids human errors.

Disadvantages:
1. Writing tests takes time.
2. Developer must apply himself and understand TDD thought processes well.
3. Timely review of the TDD process must be done and this takes time.
4. Requirements must be concise for the developer to write proper unit tests.

So that's TDD in a nutshell. We will be applying this at work. Lets see how it goes.
meanwhile the TDD framework/library we used in training is CppUTest. It's GPL and I'm thinking of doing some code, and if I do make some code then I'll publish it here.

Comments

Popular posts from this blog

Morning Quotes

QCalendarWidget CSS Stylesheeting