The essence of Test-driven development

The essence of Test-driven development (TDD) is that you think about how to verify (or test) your code when developing - designing and implementing your app in code.

Basically, the approach doesn't differ from when you otherwise would create a program, make some changes, and run it to see if it behaves as expected. Mainly that there are tools involved.

Instead of testing your program by repeatedly running it in its entirely, you create snippets of code that run that portion of the program that you want to the test.

This is your workbench were you are tinkering with your program. These snippets are your test cases where you make assertions about the behavior of a specific part of your program. - While you are developing.

These test cases that you produce can all be run to test the program in its entirety.

The purpose of a unit test is to verify the behavior of a specific unit. A unit is a component with defined purpose and behavior. You are testing behavior and not classes or methods specifically.

The point is not to write tests after the fact, but when you are designing and implementing your classes and methods.

You should write tests while developing new functionality as well to verify bug fixes. And not just verifying “happy paths” but also exceptions.

Breaking your code down into units make testing easier. And you can always mock dependencies.

A common complaint about writing unit test are that they take time to write. So does restarting your app or web service, and to find what to test every time you have made a change. Then there is the human factor.

So unit tests do save time you down the road as the code base and its complexity grows - especially while debugging.

Realistically, you don't have to cover everything in your app when doing unit testing. Just be smart about it.

#testdrivendevelopment #softwaredevelopment #unittesting #softwaredesign

要查看或添加评论,请登录

Marina Sundstr?m的更多文章

  • Scaling a Monolith - without Microservices

    Scaling a Monolith - without Microservices

    One myth is that you need to "do" microservices in order to scale your service applications horizontally. This has…

  • Microservices - What are they?

    Microservices - What are they?

    Microservices is a hot topic in software development nowadays. Everybody wants to do it, but what is the point of it?…

  • Docker and Kubernetes - An Introduction

    Docker and Kubernetes - An Introduction

    There are two pieces of software that everybody is talking about right now: Docker and Kubernetes. Docker Docker is a…

  • The political call for rationing

    The political call for rationing

    This week it was reported that the Swedish Prime Minister Stefan L?fvén had been talking to the Swedish retailer ICA…

    1 条评论
  • Defending the profit motive

    Defending the profit motive

    Profits are essential to the entrepreneurial process. Money represents the economic activity.

  • Why do we need prices?

    Why do we need prices?

    Yet another article in the series on competition, monopolies and patents. Prices are everywhere, so they must mean…

  • Do we need patents?

    Do we need patents?

    This is the continuation of my series on competition and monopolies. Now, we are going to talk about ownership and…

  • Should we fear "monopolies"?

    Should we fear "monopolies"?

    What is fair competition? What happens when a big company dominates a certain industry? This is a continuation of my…

  • Why do we need competition?

    Why do we need competition?

    This is my first article on LinkedIn. Let us de-mystify economic competition.

    4 条评论

社区洞察

其他会员也浏览了