Mappa Via Marconi 20, Bussolengo (VR)
Email info@devinterface.com

Test-driven development and continuous integration

Test-driven development e Continuous Integration

Index

Test-driven development (TDD) and Continuous Integration (CI) are two increasingly popular software development methodologies amongst developers. Both techniques aim to improve software's quality and to reduce mistakes during the development process. 

In this article, we will deepen the two techniques and discuss their advantages and disadvantages.

 

Test-driven development (TDD)

The Test First approach encourages the implementation of one of more tests verifying the implementation before the creation of functionalities. This means that several features need to be implemented in a software, there should already exist a series of tests to verify these features before the implementation starts. It is a very generic approach that leaves lot of space to interpretation: should all the tests pre-exist? Test must exist before the implementation of the function? Are unit test, service test or system test to be used?

To answer these and many other questions, at least in one case there is a concrete method to apply Test First in development. It is an approach in which the software gets developed in small iterations, piece by piece, and in each iteration the unit tests are written first, then the function and finally the source code is optimised with respect to numerous quality attributes. This is exactly what Test-driven Development (TDD) is.

 

Specifically, the sequence of TDD programming is cyclic:

  • A test is written that initially fails.

  • Exactly enough production code is implemented to successfully pass the test.

  • The test code and the production code are refactored.

 

Tests are typically implemented with the XUnit framework in the same language as the production code. Tests that pass successfully are represented by a green bar, those that do not pass with a red bar. This is therefore referred to as the 'Red-Green-Refactor' cycle.

Test-driven development proceeds incrementally. Each TDD cycle that is executed enriches the software with new functionality - and it does so meticulously, because each section of the cycle should not take more than a few minutes.

Indeed, with this Agile method, inventor Ken Beck has created the possibility of developing very stable and high-quality source code, which however also has some disadvantages.

 

Advantages

Every developer who hears about TDD for the first time is totally enthusiastic: TDD is fun, challenging to implement and guarantees a higher quality of the developed software. Three of the numerous advantages are:

  • Stability. Stability is a win-win, because in fact everyone involved is trying all day long, directly or indirectly, to achieve just that: more stable software, and indeed they are.

  • No side effects. One of the biggest fears in software development is that everything still works after a change or a bug fix. With TDD, tests can be run at any time and either everything is OK because all tests are green or it is not and the failed tests show quite quickly where the bug is.

  • Project testability. If one does not work 'test-first', but wants to test later, the main problem is usually that the class structure is not testable. With TDD, this cannot happen at all, because the features mean that the functionality can only exist if it has been tested.

 

Disadvantages

  • Costs. as much as TDD is loved by developers, funders are usually not so keen on it because TDD is rather expensive and among quality measures it is probably also the most expensive of all, but at the same time the most effective.

  • Slowness: If one looks at the pure output of functionality, development with TDD is slower than without.

  • Modifiability. The quantity of tests is another disadvantage. The expense does not only concern the creation of the tests, but especially the adjustments when, for example, the application is extended or a bug is fixed. This unfortunately makes TDD twice as expensive and therefore quality is paid for dearly.


 

Continuous Integration (CI)

Continuous integration is an agile software development concept and a fundamental component of the DevOps approach. It describes the process of continuously merging code components in a project application. Automated testing procedures provide developers with immediate feedback on their code. They can enter it into the version management system as quickly as possible, so that other project participants always have access to a stable, up-to-date version of the application.

Continuous integration is based on the regular joining of code components of developers working independently of each other in a central repository accessible to all, at best every day or even several times a day. In the repository, the code is then checked with the help of automated unit and integration tests and executed on an experimental basis in several builds. In this way, version checks are performed in which the correct functioning of the injected code is validated on a regular basis.

 

Advantages

  • Early error detection: developers can test code changes quickly and efficiently. Thus, errors can be detected and resolved early, before they are integrated into the production code. This helps to improve software quality and avoids costly bugs that have to be fixed later.

  • Faster feature delivery: changes can be quickly and seamlessly integrated into the common code base. This allows new functionality to be delivered more quickly and reduces development time, which is particularly important in agile environments where the rapid release of new functionality is crucial.

  • Better team collaboration: continuous integration promotes collaboration between teams, ensuring that changes made by all developers are integrated into the common code base. This avoids conflicts that can be caused by different code versions and creates a common understanding of code and functionality.

  • Automation: CI automates many aspects of the development process, such as testing and reviews. This minimises manual errors and increases developer productivity.

  • Better code quality: the continuous integration of code changes and tests improves code quality. Errors can be quickly detected and corrected, which increases the stability of the software and facilitates maintainability.

 

Disadvantages

  • Creation of an appropriate technical infrastructure: CI implementation involves a number of supporting technologies, such as version control systems, hosting infrastructure and orchestration technologies. It also requires the creation of additional servers and environments for testing and compilation processes.

  • Familiarisation of development teams with the new processes: since the added value of continuous integration depends on the quality of the tests performed, appropriate test procedures must be developed and distributed in a test suite. The creation of this automated test suite involves a lot of work and must be continuously developed to cover new functionalities and keep track of planned code changes. The same applies to setting up compilation systems, which can become very complex, making flexible adaptation difficult.

 

Conclusion

Summing up, Test-driven development (TDD) and Continuous Integration (CI) are two software development methodologies that can improve code quality, increase the efficiency of the development team and reduce software maintenance costs. By using them together, developers can guarantee a product that is always tested, integrated and ready for production. In short, the benefits of these methodologies are undeniable. What do you think? Is your development team already implementing the use of TDD or CI? Let us know your opinion by leaving a comment!