Test Driven Development (TDD) is a proven technique that will increase the quality of your code. Check out how to use this technique in Python.

Bugs! Every application has it and no matter how careful you are you will create one sooner or later. Especially if you are working on large enterprise software. Now, I know a bunch of people have a “My code is clean and bugless” attitude, but creating bug-free code is extremely hard if not impossible. However, that doesn’t mean that you should give up and just write spaghetti code that just doesn’t work. We – developers, should give our best to write high-quality code. High-quality means a low number of bugs, among other things.

Apart from that, having a bug in production is extremely expensive. You probably know that comparison, where a bug found during development is 100 times cheaper than finding the same bug during production. So, we should focus on finding our bugs as soon as possible. Our first line of defense is testing. That is a scary metric.

We could test our applications manually, just by running them and clicking around. However, this approach has many pitfalls. The first one is that it is time-consuming, which basically means expensive. This way of testing makes regression testing extremely hard too.

Imagine that you’ve just added a new feature to your application. You will have to make sure that this new feature didn’t break any of the old functionalities, which means testing your whole application from the beginning. Again, time-consuming and costly. What is the solution? Automated testing of course.

In this article we cover:

  1. Automated Tests
  2. Unit Tests
  3. What is Test-Driven Development?
  4. Solving a problem with TDD and Python
  5. Mock Objects
  6. Patching

#python #testing

Test Driven Development (TDD) with Python
2.90 GEEK