Thinking 'Behavior' and 'Feedback' through TDD

Gain efficiency and quality with Test Driven Development

Featured Image
TDD: Kezako ?🤔

Test-driven development (TDD) refers to a software development technique that aims to reduce anomalies in an application by promoting frequent implementation of tests. A test-first policy, consistent with agile methods, that urges programmers to be more rigorous and to correct bugs and other errors in the source code in almost real time. Initially, test-driven development suggests designing tests before even developing using the test-first design approach.
It adds quality to the code produced while documenting it. This facilitates maintenance and ensures the safety of future modifications. In the developer community, TDD is often known as a waste of time because writing tests takes time and this is like writing double code (the one for tests and the one to be tested). Opinions are quite divided on the subject where on the one hand we will have the purists who only swear by the TDD, then the neutrals who will use it from time to time and finally the opponents who do not use it at all.

A. Test-Driven Development Context (TDD)

While development granularity was a detail when building software, today it isined thanks to TDDs with growth adoption by companies since 2015 (more than 80% of tech companies adopt TDD). In 2003, Kent Beck democratized TDD in his book "Test-Driven Development: By Example", after experimenting with and promoting these ideas in 1990 through the Extreme Programming (XP) movement, which aimed to popularize TDD-related practices.

Thanks to his brilliant work, the community is increasingly interested in this method and a plethora of test tools are emerging. The principle of this method is to focus on the behaviors in order to provide a quick and quality feedback. To do this, we have to make sure at every minor iteration that the code produced is useful (so that there is no dead code), has the expected behavior and does not break existing behaviors.

II. Privileged "behavior" in TDD

The great misfortune of developers is to think "technical" and not "handicraft" because system modelling is extremely poorly taught. Nowadays, when you start a project, you tend to lean directly on the technologies to use instead of focusing on the business aspects of the system, making it difficult to adopt TDD because it is a complex exercise of abstraction that most people are not used to.
When you want to take advantage of TDD, it is more than necessary to encapsulate all the business rules that will make up the application before thinking about what is called implementation details.

When we ensure that our business specifications are functional thanks to the approval of the tests, we can add other layers in complete serenity. Focusing on behavior allows us not only to be effective, but also to be able to quickly iterate on application features without regression.

III. Importance of Information Feedback in TDD

Feedback is a key element in TDD and sometimes neglected by developers which ends up catching them. A few years ago, I was developing REST APIs and testing it with software like Postman or Insomnia. This practice works very well, but on small-scale projects. I was faced with a large-scale project in my company and that's where I got a wall. Every time we had to start all the services, start the server, make sure everything is up, make the request from the postman.

If there was a problem, looking at the console and sometimes tracing the source of the problem is impossible because we have no control over the execution flow so we are not forced to launch a debugger that we have to configure depending on the project we are working on. It is very quickly understood with this practice that the return of information is too late.

We're testing an entire chain, but we'd just like to test a piece of that chain which results in sometimes inconsistent results. On the other hand, by treating the problem by granularity, one can ensure that each brick plays its expected role and that the whole works properly.

IV. Comment j'ai tiré profit du TDD ?

Like any engineer, we need to find effective solutions that not only worked, but also enable us to be more productive by focusing only (in real life, I'll say "most often" ) on the high impact aspects. Today, there are many tools that enable us to quickly set up an environment with what is right, but we still have to distinguish between what we really need and what we should focus on. During my stay at Azatys, I was able to speak on various projects in the company.

One of the most important was the Azatys platform, which relied on a complex process of tracking digital indicators of the websites and social networks of customers and their competitors. This tracking module uses many services, including Azatys' API to perform a number of business calculations. All the added value of the company is based on these calculations, so it is strong to note that my enthusiasm was going to focus on the strict operation of this business aspect before the cherry on the gateau.

This is where TDD intervenes to enable me to carry out this task safely and with quick feedback. By defining business rules with industry professionals, this allows me to write tests on which my solution will be based to ensure that it carries all defined business specifications. Similarly, TDD is a perfect match with agile project management methods, because with quick feedback, you can deploy releases regularly to users and iterate without regression. This is how TDD allowed me (with more than 2 years of practice), to set up a module that wants to be complex in all serenity.

References:

  • D. Melton, "Design Systems Thinking for Innovation in an Engineering Faculty Development Program", 2021
  • Evan Rusoja, R. Chad Swanson, Mini Swift, "Using Systems Thinking and Complexity Theory to understand and improve Emergency Medicine: Lessons from COVID-19 in a safety net health system.", 2023
  • Anna C. Schneider, O. Itani, Elizabeth M. Cronin, Dirk Bucher, F. Nadim, "the ANN "Evolution of the arthropod brain - from development to structure" Final Program", 2022
  • Umaporn Yamubon, Therdpong Thongseiratch, "Using a Design Thinking Approach to Develop a Social Media-Based Parenting Program for Parents of Children With Attention-Deficit/Hyperactivity Disorder: Mixed Methods Study", 2023