Fit Refactoring-Improving the Quality of Fit Acceptance Test
Total Page:16
File Type:pdf, Size:1020Kb
FIT REFACTORING-IMPROVING THE QUALITY OF FIT ACCEPTANCE TEST Xu Liu A Thesis Submitted to the graduate college of Bowling Green State University in partial fulfillment of The requirement for the degree of Master of Science August 2007 Committee: Joseph Chao, Advisor Ron Lancaster Mohammad Dadfar ii ABSTRACT Joseph Chao, Advisor Acceptance tests are formal testing conducted to determine whether a system satisfies its acceptance criteria or not and whether the acquirer should accept the system or not. A suite of acceptance tests for large projects might include a large number of test cases; therefore, automation of acceptance test is in great demand. Framework for Integrated Tests (FIT) is a popular tool employed in Agile Software Development to automate acceptance tests. Its most attractive feature is that it uses customer readable tables as test cases so that customers can write test cases. Refactoring is the process of restructuring or rewriting code without changing its interface and functionality. Refactoring make the code easier to read, understand and maintain, and sometime helps to improve the performance of the system. In a typical project that uses FIT as an acceptance test tool, the size of FIT acceptance tests grows as the size of system code grows, and the acceptance design may go far away from the original design (this may happen in any project, not restricted in a project using FIT). At this stage, it would be difficult to read and maintain the FIT acceptance test, and it is time to improve the quality of the acceptance test. In this research, we introduce the concept and reveal the importance of FIT Refactoring. Several FIT Refactoring methods are introduced as examples to show the needs of FIT Refactoring and the methods how it can be accomplished. Of course, the methods given here are some obvious refactoring methods, and new methods can be discovered in further research. We iii also discuss the proper time to do FIT refactoring and proper efforts that should be devoted in it. The similarities and differences between system code refactoring and FIT acceptance test refactoring are also one part of the research. During the research, there are some unexpected findings. One of them is that sometimes, the bad code in FIT acceptance test indicates bad code in the system code. iv ACKNOWLEDGMENTS I would like to give some sincere thanks to my adviser, Dr. Joseph Chao. Without his guidance and support, it would be impossible for me to complete this research. His experience in research, willingness to help and patience are great helps to me. I also want to thank my committee members, Dr. Ron Lancaster and Dr. Mohammad Dadfar for reading and providing valuable suggestions to this research. v TABLE OF CONTENTS Page TABLE OF CONTENTS........................................................................................................ v LIST OF FIGURES .............................................................................................................. vii LIST OF TABLES...............................................................................................................viii LIST OF TABLES...............................................................................................................viii CHAPTER 1 INTRODUCTION.......................................................................................... 1 1.1 Agile Software Development ................................................................................. 1 1.2 Acceptance tests ..................................................................................................... 2 1.3 Framework for integrated tests (FIT) ..................................................................... 3 1.4 Refactoring ............................................................................................................. 8 CHAPTER 2 LITERATURE REVIEW............................................................................. 11 2.1 Acceptance Test and FIT...................................................................................... 11 2.2 Refactoring on System Code and Test Code........................................................ 16 CHAPTER 3 FIT REFACTORING................................................................................... 19 3.1 Why FIT Refactoring ........................................................................................... 19 3.2 Table Refactoring and Fixture Refactoring.......................................................... 21 3.3 When to do FIT Refactoring ................................................................................ 23 CHAPTER 4 METHODS OF FIT REFACTORING ........................................................ 26 4.1 FIT refactoring methods on tables........................................................................ 27 vi 4.1.1 Rename........................................................................................................ 27 4.1.2 Introducing new domain concept ................................................................ 30 4.1.3 Extract similar part of tables into fixture..................................................... 33 4.1.4 Merge tables ................................................................................................ 36 4.1.5 Split table..................................................................................................... 38 4.2 FIT refactoring methods on fixtures..................................................................... 40 4.2.1 Merge similar methods................................................................................ 40 4.2.2 Extract method ............................................................................................ 43 4.2.3 Extract similar methods in fixture into new class ....................................... 45 CHAPTER 5 OTHER FINDINGS..................................................................................... 49 5.1 Improper FIT acceptance test may indicate improper system code ..................... 49 5.2 Recommendation on organization of FIT acceptance test table........................... 51 CHAPTER 6 CONCLUSION............................................................................................ 57 REFERENCES ..................................................................................................................... 59 vii LIST OF FIGURES Figure Page Figure 1-1 FIT acceptance Test Case Sample......................................................................... 5 Figure 1-2 FIT acceptance Test Fixture Sample..................................................................... 6 Figure 1-3 FIT acceptance Test Result Sample ...................................................................... 8 Figure 4-1 Part of AddInventory Fixture.............................................................................. 28 Figure 4-2 AddInventory Fixture Before Refactoring.......................................................... 29 Figure 4-3 AddInventory Fixture After Refactoring ............................................................ 29 Figure 4-4 Refactored purchaseBeverageNew Table ........................................................... 36 Figure 4-5 EditRecipe Fixture Before Refactoring............................................................... 42 Figure 4-6 EditRecipe Fixture Before Refactoring............................................................... 42 Figure 4-7 PurchaseBeverage Before Refactoring ............................................................... 45 Figure 4-8 PurchaseBeverage After Refactoring.................................................................. 45 Figure 4-9 PurchaseBeverage Before Refactoring ............................................................... 46 Figure 4-10 setDefaultRecipes Class.................................................................................... 47 Figure 4-11 purchaseBeverageNew Fixture ......................................................................... 47 Figure 4-12 PurchaseBeverage Test Case............................................................................. 48 Figure 5-1 coffeeMaker Class Diagram................................................................................ 50 Figure 5-2 Part of setUpCoffeeMaker Fixture...................................................................... 50 viii LIST OF TABLES Table Page Table 4-1 Part of AddInventory Test Case ........................................................................... 28 Table 4-2 AddInventory Table Before Refactoring.............................................................. 29 Table 4-3 AddInventory Table After Refactoring ................................................................ 29 Table 4-4 offteredServices Table.......................................................................................... 31 Table 4-5 lineCapability Table ............................................................................................. 31 Table 4-6 The Refactored offeredServices Table ................................................................. 32 Table 4-7 New offteredServices Table ................................................................................. 32 Table 4-8 New offeredServices Table After Refactoring..................................................... 33 Table 4-9 purchaseBeverageNew table ................................................................................ 35 Table 4-10 CalculateCredit table .........................................................................................