Test – Code – Refactor – Repeat: A quick look on TDD
Can you spot the difference? Likely i start coding before testing, hell – often i start coding before the requirements are fixed… Code – Requirements – Refactor – GoLive – Test
But there is a better way… TDD.
TDD stands for Test-Driven Development. It is a software development process in which tests are written for new code before the code is written. The code is then written to pass the tests, and the process is repeated for each new feature or bug fix. The goal of TDD is to catch errors early in the development process and to improve the design and quality of the code. It is connected to “Modern ABAP” and “Clean Code” as described in: Clean ABAP – Testing. TDD is an agile development process that has its origins in Extreme Programming (XP) and was first formally described by Kent Beck in his book “Test-Driven Development by Example” in 2002. The process was later popularized in the Agile software development community, and it has become a staple of many Agile methodologies such as Scrum, Kanban and Lean Software Development.
However – as everything in live – TDD comes with a catch: It takes time to create the test cases upfront, you really need to know what to develop (the opening sentence was not a joke) – and the test might become over-specified and – last but not least – most developers need to leave their comfort zone….
The steps in the development cycle are:
1) Pick a task or function
2) Write a test for it
3) Run the tests – the new one should fail
4) Write the code to complete the task/function
5) Re-Run the tests – they should now all pass
6) Refactor
7) Repeat
Or Short: Test – Code – Refactor – Repeat
In the SAP area there are several built-in tools to support TDD, like:
– ABAP Unit
– ATC (ABAP Test Cockpit)
– ABAP Test Double Framework
Academic papers on TDD:
– Hosseini, Rebvar & Turhan, Burak & Gunarathna, Dimuthu. (2017). A Systematic Literature Review and Meta-Analysis on Cross Project Defect Prediction. IEEE Transactions on Software Engineering. PP. 1-1. 10.1109/TSE.2017.2770124.
– Munir, H., Moayyed, M., & Petersen, K. (2014). Considering rigor and relevance when evaluating test driven development: A systematic review. Information and Software Technology, 56(4), 375-394.
– Gmeiner, J., Ramler, R., & Haslinger, J. (2015, April). Automated testing in the continuous delivery pipeline: A case study of an online company. In 2015 IEEE Eighth International Conference on Software Testing, Verification and Validation Workshops (ICSTW) (pp. 1-6). IEEE.
See also:
open.sap – Writing Testable Code for ABAP
https://community.sap.com/topics/abap-testing-analysis
1 Response
[…] cornerstone if the organization wants to realize CI/CD and be truly “agile”. See this post about TDD for more… However reality looks different: At the 2022 DSAG “Technologietage” the […]