Unit Testing of Java EE Web Applications
Total Page:16
File Type:pdf, Size:1020Kb
Unit Testing of Java EE Web Applications CHRISTIAN CASTILLO and MUSTAFA HAMRA KTH Information and Communication Technology Bachelor of Science Thesis Stockholm, Sweden 2014 TRITA-ICT-EX-2014:55 Unit Testing of Java EE Web Applications Christian Castillo Mustafa Hamra Bachelor of Science Thesis ICT 2013:3 TIDAB 009 KTH Information and Communication Technology Computer Engineering SE-164 40 KISTA Examensarbete ICT 2013:3 TIDAB 009 Analys av testramverk för Java EE Applikationer Christian Castillo Mustafa Hamra Godkänt Examinator Handledare 2014-maj-09 Leif Lindbäck Leif Lindbäck Uppdragsgivare Kontaktperson KTH/ICT/SCS Leif Lindbäck Sammanfattning Målet med denna rapport att är utvärdera testramverken Mockito och Selenium för att se om de är väl anpassade för nybörjare som ska enhetstesta och integritetstesta existerande Java EE Webbapplikationer. Rapporten ska också hjälpa till med inlärningsprocessen genom att förse studenterna, i kursen IV1201 – Arkitektur och design av globala applikationer, med användarvänliga guider. ii Bachelor thesis ICT 2014:6 TIDAB 009 Unit Testing of Java EE web applications Christian Castillo Mustafa Hamra Approved Examiner Supervisor 2014-maj-09 Leif Lindbäck Leif Lindbäck Commissioner Contact person KTH/ICT/SCS Leif Lindbäck Abstract This report determines if the Mockito and Selenium testing frameworks are well suited for novice users when unit- and integration testing existing Java EE Web applications in the course IV1201 – Design of Global Applications. The report also provides user-friendly tutorials to help with the learning process. iii PREFACE The report is a Bachelor Thesis that has been written in collaboration with the Department of Software and Computer Systems (SCS), School of Information and Communication Technology (ICT), Royal Institute of Technology (KTH). The purpose of this thesis is to analyze which unit testing frameworks and integration testing frameworks are well suited for Java EE applications for the course Design of Global Applications, IV1201. Being an academic report meant a close cooperation with our supervisor/examiner. Specifically, this study meant acquiring a strong grasp on the different frameworks such as Mockito framework extension over JUnit or JSFUnit, before implementing these on our previous Java EE code projects from when we attended the course. With this in mind, we like to thank our examiner and supervisor Leif Lindbäck at the Royal Institute of Technology (KTH) for his immense support and time dedicated into helping us throughout the project. Christian Castillo and Mustafa Hamra Stockholm, June 2014 iv NOMENCLATURE Abbreviations CDI Context Dependency Injection GUI/UI Graphical User Interface/User Interface HCI Human-Computer Interaction ICT Information and Communications Technology IDE Integrated Development Environment IMRaD Introduction, Method, Results and Discussion KTH Royal Institute of Technology OS Operating System OSGi Open Services Gateway Initiative PC Personal Computer SCS Software and Computer Systems SUT System Under Test TDD Test-Driven Development URL Uniform Resource Locator XP Extreme Programming v TABLE OF CONTENTS PREFACE ..................................................................................................................... IV NOMENCLATURE ......................................................................................................... V 1 INTRODUCTION .......................................................................................................... 1 1.1 BACKGROUND .................................................................................................................. 1 1.2 PURPOSE........................................................................................................................... 1 1.3 DELIMITATIONS ................................................................................................................ 2 1.4 METHOD ........................................................................................................................... 3 1.5 DISPOSITION ..................................................................................................................... 4 2 FRAME OF REFERENCE ............................................................................................ 5 3 THEORY ....................................................................................................................... 6 3.1 UNIT TESTING ................................................................................................................... 6 3.2 INTEGRATION TESTING ..................................................................................................... 7 3.2.1 Big Bang Approach ..................................................................................................... 7 3.2.2 Top-down Approach .................................................................................................... 9 3.2.3 Bottom-up Approach ................................................................................................. 11 3.3 MOCKITO ....................................................................................................................... 12 3.4 SELENIUM ...................................................................................................................... 14 4 THE PROCESS .......................................................................................................... 17 4.1 TEST CASES .................................................................................................................... 17 4.1.1 Test the logger ........................................................................................................... 17 4.1.2 Test of login method .................................................................................................. 18 4.1.3 Test of getters and setters .......................................................................................... 20 4.1.4 Test of login interaction ............................................................................................ 21 4.1.5 Test the login interaction & update status ................................................................ 22 4.1.6 Test of creating an application .................................................................................. 22 4.2 TUTORIALS ..................................................................................................................... 23 5 RESULTS ................................................................................................................... 25 5.1 MOCKITO TEST RESULTS ............................................................................................... 25 5.1.1 Results for test case: Test the logger ......................................................................... 25 5.1.2 Results for test case: Test of login method ................................................................ 28 5.1.3 Results for test case: Test of getters and setters ........................................................ 30 5.2 SELENIUM TEST RESULTS .............................................................................................. 33 5.2.1 Results for test case: Test of login interaction .......................................................... 33 5.2.2 Results for test case: Test of login interaction & update status ................................ 34 5.2.3 Results for test case: Test of creating an application ............................................... 35 5.3 EVALUATION OF TUTORIALS .......................................................................................... 37 5.3.1 Resulting structure of tutorials .................................................................................. 37 6 DISCUSSION AND CONCLUSIONS ......................................................................... 39 6.1 DISCUSSION OF TEST CASE RESULTS ............................................................................... 39 6.1.1 Discussing results for test case: Test the logger ....................................................... 39 6.1.2 Discussing results for test case: Test of login method .............................................. 40 6.1.3 Discussing results for test case: Test of getters and setters ...................................... 42 vi 6.1.4 Discussing results for test case: Test of login interaction ........................................ 43 6.1.5 Discussing results for test case: Test of login interaction & update status .............. 43 6.1.6 Discussing results for test case: Test of creating an application .............................. 43 6.2 DISCUSSION OF TUTORIALS ............................................................................................ 44 6.2.1 Tutorial for Mockito .................................................................................................. 44 6.2.2 Tutorial for Selenium ................................................................................................ 45 6.3 CONCLUSION .................................................................................................................. 47 6.3.1 Frameworks ............................................................................................................... 47 6.3.2 Tutorials .................................................................................................................... 47 7 RECOMMENDATIONS AND FUTURE WORK .......................................................... 48 7.1