
UNIVERSITY OF HERTFORDSHIRE Faculty of Engineering and Information Sciences 7WCM0003 Computer Science MSc Project (Online) Final Report January 2017 An Investigation into Introducing Test-Driven Development into a Legacy Project P. Hall ABSTRACT Background Test-Driven Development is a development technique that is said to produce code that is less complex, highly cohesive and easy to maintain compared to traditional development methods. TDD was introduced into a legacy application that had no testing in place, which allowed users to generate their own content and was developed in the .Net MVC framework. Objective To determine if adding new functionality to a legacy project with Test-Driven Development improves the internal code quality. Method New functionality was added to a legacy application using Test-Driven Development. Code metrics were recorded at the start of the project and after every iteration of development. The results were then compared to establish if any difference could be seen in the metric values before and after introducing TDD. Results Test-Driven Development marginally had negative impacts on average lines of code, coupling and complexity but it had a slight positive impact upon maintainability and cohesion. None of these differences were significant. Conclusion Test-Driven Development has little to no impact on improving the internal code quality of .Net legacy application. However, it did significantly increase the test coverage of the project, which can lead to a reduction in the error proneness of the application and an improvement in external code quality. ii ACKNOWLEDGEMENTS I would like to give thanks to my supervisor who helped me to formalise my ideas and was always on hand to give advice. I would also like to thank my loving family for their continued support throughout the project and their understanding for all those long nights and weekends spent away from them. iii CONTENTS 1. Introduction ............................................................................................................ 1 1.1 Background ........................................................................................................ 1 1.2 Research Questions ........................................................................................... 3 1.3 Objectives .......................................................................................................... 3 1.4 Methodology ..................................................................................................... 4 2. Related Work ........................................................................................................... 6 3. Test-Driven Development ..................................................................................... 11 3.1 Overview of TDD ............................................................................................. 11 3.2 TDD Tools in .Net ............................................................................................. 12 3.3 Methods and Techniques for TDD and Legacy Code ....................................... 21 4. Measuring Software Quality .................................................................................. 24 4.1 What Makes Good Software? ......................................................................... 24 4.2 Software Metrics Used for Project .................................................................. 25 4.3 Software Metric Tools in .Net ......................................................................... 31 5. Legacy Project ....................................................................................................... 37 5.1 Overview of Application .................................................................................. 37 5.2 Development Plan ........................................................................................... 37 6. Development Challenges and Solutions ................................................................ 41 7. Results ................................................................................................................... 47 7.1 Software Metrics ............................................................................................. 47 7.2 Code Test Coverage ......................................................................................... 52 8. Conclusion ............................................................................................................. 55 8.1 Summary and Evaluation ................................................................................. 55 8.2 Future Work .................................................................................................... 56 References ................................................................................................................. 57 Appendix A ................................................................................................................ 63 Appendix B ................................................................................................................ 66 Appendix C ................................................................................................................ 67 Appendix D ................................................................................................................ 69 iv 1. INTRODUCTION 1.1 Background Test-Driven Development (TDD) is an approach to developing software were test code is written first before writing production code to fulfil the test. It relies heavily upon refactoring whilst providing a safety net of tests that can be run each time the code is changed (Crispin 2006) and is not just a testing technique but a process incorporating many different methods such as unit, acceptance, performance and system integration tests (Desai et al. 2008). TDD follows a red-green-refactor cycle in which a test is written that fails (red), production code is written that passes (green) and finally that code is refactored if necessary (refactor), this cycle formulates a continuous rhythm for the lifecycle of the project (Beck 2002). TDD is an increasingly popular paradigm in software engineering especially with the advent of agile processes over the past two decades. It is a highly sought after practice in the job market with its citation on IT job adverts in the UK increasing year on year (ITJobsWatch 2016), but it can also be a daunting practice to begin for those new to the technique (Crispin 2006). However, a recent study shows that skilled developers with no prior experience of TDD can quickly learn and properly apply the methods (Latorre 2014). Despite this increase in popularity, heavy links to agile methodologies and apparent ease to adopt, a 2013 survey shows that less than 40% of agile teams employ a TDD approach (Ambler 2013a). 1 Figure 1 - shows how TDD as a job requirement has increased greatly over the past decade (IT Jobs Watch, 2016) Figure 2 - 2013 Ambysoft “how agile are you?” survey results showing less than 40% employ a TDD approach (Ambler 2013b) A systematic review by Bissi et al. (2016) on the effects of TDD on code quality and productivity found that most of the current work on the subject has so far focused on examining external code quality by using the Java programming language to develop new projects. The review suggests that relatively little work has been done 2 to investigate TDD in legacy projects and states that there is scope for research into how TDD impacts internal code quality using a set of code analyse metrics as well as how TDD extends to alternative languages other than Java. This project was built upon the work of studies such as Guerra’s (2014), where an investigation to give an overview of the process of developing a complex framework using TDD practises was undertaken. The study used code metrics to analyse how the framework evolved over time and provided a detailed documentation of the challenges encountered during the development process. This project used a similar technique but investigated how TDD influenced the code quality of a legacy project. 1.2 Research Questions 1. Does introducing Test-Driven Development into a legacy project improve the internal code quality? 2. What are the challenges and solutions of implementing Test-Driven Development practices into a legacy project? 3. What are the advantages and disadvantages of the different tools available for implementing Test-Driven Development in the .Net framework? 4. Do different code metric measuring tools provide different results for the same code base? 1.3 Objectives • Complete a literature search and review of existing work regarding Test-Driven Development and legacy projects • Identify and evaluate the available approaches for introducing Test-Driven Development into a legacy project • Compare and evaluate the most popular tools for Test-Driven Development inside the .Net framework • Extend the legacy project by implementing completely new functionality and advanced web 2.0 features using Test-Driven Development • Analyse the effect Test-Driven Development has upon the internal code quality of the project • Provide documentation of the project experience and development including any challenges encountered and the solutions used 3 • Analyse the project code coverage and number of unit tests introduced using Test- Driven Development • Compare the results of software metric tools for .Net 1.4 Methodology The research for this project applied known methodologies to a new case study, namely applying
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages74 Page
-
File Size-