30.08.22
by Tamas Hortobagyi
With a test-driven approach to software development, teams can work more efficiently to write code with fewer bugs and reduce the need to change lots of code. Tamas Hortobagyi, Engineering Lead of Video Experiences, explains the basics of Test Driven Development and how we applied it when working with BritBox UK
30.08.22
by Tamas Hortobagyi
With a test-driven approach to software development, teams can work more efficiently to write code with fewer bugs and reduce the need to change lots of code. Tamas Hortobagyi, Engineering Lead of Video Experiences, explains the basics of Test Driven Development and how we applied it when working with BritBox UK
Traditionally, developers write code and then test it. Test Driven Development (TDD) reverses this process: testing happens first, and then the code is written.
Developers create unit tests before developing code in an iterative process that combines coding, writing unit tests and refactoring.
TDD works by creating a test case for each feature of a product. When the test fails, the developers write or modify the code. This approach prevents duplication of test scripts and allows developers and testers to create optimized and resilient code.
TDD fosters the creation of optimized code, can streamline software development, enhance productivity, and lead to a flexible codebase that is easy to maintain.
A TDD workflow helps our developers to analyze and understand a client's requirements and request clarity where they are not adequately defined.
Adding and testing new functionalities becomes much easier in the later stages of development. Additionally, because TDD focuses on creating tests for each functionality right from the start, test coverage under TDD is much higher when compared to the conventional development models.
TDD works in small increments where:
Before writing any unit tests, the first step is to review and test the requirements. The aim is to consider all the possibilities and understand what needs testing before designing the tests.
For example, a single requirement could be one of many examples that could occur. Or there could be instances where it could be wrong.
This step will help improve the design and code quality from the start; rather than fixing bugs in a reactive approach.
Before writing the test scenarios, ensure you review the unit testing strategy. This will help you assign the risk associated with the module being tested and will save time on rewriting code later on.
Now that you know what you want to test and how intensively, the next step is to consider the risks and their priorities.
A risk is the probability of an occurrence of an uncertain event which could impact the business, cost or the quality or technical targets of the project. The risk could be a current, past or future event.
Calculating the risk rating helps us decide how many unit tests to write. The higher the priority, the higher the test coverage will be.
A risk assessment matrix provides the project team with a handy overview of the risks and the priority in which they should address them. To work out the risk rating, we need to look at probability and severity.
Probability is the chance of an uncertain event occurring, which we measure as a percentage:
Severity is the degree of impact an uncertain event causes and are classified as:
Once we know the probability and severity, we can map these into four categories in the risk assessment matrix: High, Serious, Medium and Low. Risks falling into High or Serious must be dealt with immediately.
Here at Deltatre, we find a TDD approach works well for many of our projects, including when we worked with ITV to create the BritBox OTT platform.
BritBox UK is a niche streaming video on demand (SVOD) service by BBC and ITV. It aims to address a specific content category and bring the very best in past, present, and future British programming and award-winning content to viewers all in one place.
At launch, we worked with BritBox UK to offer access to the BritBox app across different platforms, including Responsive Web, Android, iOS, Samsung and Apple TV. Later we added YouView, Fire TV, Freeview Play, Roku and Chromecast, with more planned for the future.
The brief from ITV was:
From the start of the project, we needed to bring the separate platform teams together to work as a whole team. Adding TDD created a good point to start conversations and introduce standards.
TDD worked well for the BritBox UK project and helped the development teams to work together. However, we didn’t use just TDD alone; we also asked the developers to own and test their code thoroughly. By working in this way, we were able to reduce bugs and reopens of the tickets.