Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

How to Test Enterprise Java Applications

6 868 vues

Publié le

Presentation I showed in LinuxTag 2012 about writing

Publié dans : Technologie

How to Test Enterprise Java Applications

  1. 1. How to Test Enterprise Java ApplicationsAlex Soto BuenoComputer Engineer
  2. 2. World Is ChangingThe World Is Changing So Fast {text/html} Client Protocol Server Persistence 2
  3. 3. World Is ChangingThe World Is Changing So Fast {text/html} Client Protocol Server Persistence 2
  4. 4. World Is ChangingThe World Is Changing So Fast {text/html} Client Protocol Server Persistence 2
  5. 5. World Is ChangingThe World Is Changing So Fast {text/html} {app/json} Client Protocol Server Persistence 2
  6. 6. World Is ChangingThe World Is Changing So Fast {text/html} {app/json} {app/xml} Client Protocol Server Persistence 2
  7. 7. World Is ChangingThe World Is Changing So Fast {text/html} {app/json} {app/xml} Client Protocol Server Persistence 2
  8. 8. World Is ChangingThe World Is Changing So Fast {text/html} {app/json} {app/xml} Client Protocol Server Persistence 2
  9. 9. World Is Changing Testing Frameworks are Changing Too 3
  10. 10. Bio Alex Soto Bueno Computer Engineer Diagnostic Grifols Compiler Tutor Active Blogger & Speaker 4
  11. 11. Overview Unit Tests - 80 % of code 5
  12. 12. Overview Unit Tests - 80 % of code Integration Tests - 15 % of code 5
  13. 13. Overview Unit Tests - 80 % of code Integration Tests - 15 % of code Acceptance Tests - 5 % of code 5
  14. 14. Unit Tests Tests small pieces of production code 6
  15. 15. Unit Tests Tests small pieces of production code Confidence to Change 6
  16. 16. Unit Tests Tests small pieces of production code Confidence to Change Quick Feedback 6
  17. 17. Unit Tests Tests small pieces of production code Confidence to Change Quick Feedback Documentation 6
  18. 18. Unit Tests FIRST Important Rules 7
  19. 19. Unit Tests Fast 8
  20. 20. Unit Tests Fast Resist Temptation 8
  21. 21. Unit Tests Isolation 9
  22. 22. Unit Tests Repeatable 10
  23. 23. Unit Tests Self-Validating 11
  24. 24. Unit Tests Timely 12
  25. 25. Unit TestsDifferent Layers - Different Frameworks 13
  26. 26. Client Side JS TestDriver xUnit approach to JavascriptApache License 2.0 14
  27. 27. Client Side JS TestDriver xUnit approach to JavascriptApache License 2.0 code 14
  28. 28. Client Side JS TestDriver xUnit approach to JavascriptApache License 2.0 code fixtures 14
  29. 29. Client Side JS TestDriver xUnit approach to JavascriptApache License 2.0 code fixtures configuration 14
  30. 30. Client Side JS TestDriver xUnit approach to JavascriptApache License 2.0 code fixtures JSTestDriver Server configuration 14
  31. 31. Client Side JS TestDriver xUnit approach to JavascriptApache License 2.0 code fixtures JSTestDriver Server browsers configuration 14
  32. 32. Client SideSinon.js mocking library for JavascriptBSD License 15
  33. 33. Client SideSinon.js mocking library for JavascriptBSD Licensesinon.stub(jQuery,“ajax”).yieldsTo(“success”,’{“name”:”Alex”}’); 15
  34. 34. Demo 16
  35. 35. Server SideUnit Test Framework for Java Common Public License 17
  36. 36. Server SideHamcrest is about expressiveness New BSD License 18
  37. 37. Server SideHamcrest is about expressiveness New BSD LicenseString officerRank = getRankByDate(officer);List<String> ranks = [(“Captain”, “Commander”)];assertEquals(true, ranks.contains(officerRank)); 18
  38. 38. Server SideHamcrest is about expressiveness New BSD License 18
  39. 39. Server SideHamcrest is about expressiveness New BSD LicenseString officerRank = getRankByDate(officer);assertThat(officerRank,isOneOf(“Captain”,”Commander”));assertThat(age, is(10));assertThat(name, is(not(“Alex”));assertThat(calculated, isNotANumber()); 18
  40. 40. Server SideSimple & Clean Mock API MIT License 19
  41. 41. Server SideSimple & Clean Mock API MIT License@Mock private OfficerDao officerDao;...MockitoAnnotations.initMocks(this);...when(officerDao.findOfficerByAge(22)) .thenReturn(newOfficer);when(officerDao.findOfficerByAge(greaterThan(50))) .thenThrow(new OldOfficerException()); 19
  42. 42. Persistence Side RDBMS are Homogeneous NoSQL are Heterogeneous 20
  43. 43. Persistence Side (SQL)Avoid HIT Database 21
  44. 44. Persistence Side (SQL)Avoid HIT Database In-Memory Databases 21
  45. 45. Persistence Side (SQL)Avoid HIT Database In-Memory Databases Apache License 2.0 BSD License * MPL 1.1 & EPL 1.0 21
  46. 46. Persistence Side (SQL) Isolation problem with Database Insert-Delete Problem 22
  47. 47. Persistence Side (SQL) Isolation problem with Database Insert-Delete Problem GNU LGPL 2.1 22
  48. 48. Persistence Side (SQL) Isolation problem with Database Insert-Delete Problem GNU LGPL 2.1 Define base data set 22
  49. 49. Persistence Side (SQL) Isolation problem with Database Insert-Delete Problem GNU LGPL 2.1 Define base data set@BeforeDatabaseOperation.CLEAN_INSERT.execute(connection,dataSet); 22
  50. 50. Persistence Side (NoSQL) 23
  51. 51. Persistence Side (NoSQL) GNU AGPL v3.0 No Embedded (in-memory) Mode (SERVER - 1153) No Test Isolation Framework 24
  52. 52. Persistence Side (NoSQL)GPL v3 & AGPL v3 Embedded (in-memory) Mode Partially supported 25
  53. 53. Persistence Side (NoSQL) DBUnit for NOSQL Apache License 2.0 26
  54. 54. Persistence Side (NoSQL) DBUnit for NOSQL MongoDb Apache License 2.0 Neo4J CouchDb Cassandra 26
  55. 55. Demo 27
  56. 56. Integration Tests Test Collaboration Between Components 28
  57. 57. Integration Tests Test Collaboration Between Components Database IO system Special Environment Configuration 28
  58. 58. Integration Tests Common Problems in JEE 6 CDI - @EJB, @Inject, @PersistenceContext 29
  59. 59. Integration Tests Common Problems in JEE 6 CDI - @EJB, @Inject, @PersistenceContext Container Lifecyle Management Create Deployment Archive 29
  60. 60. Integration Tests Common Problems in JEE 6 k oc CDI - @EJB, @Inject, @PersistenceContext M T Container Lifecyle Management NO Create Deployment Archive Do 29
  61. 61. Integration TestsArquillian brings tests to runtime Manage Lifecycle of Container Apache License 2.0 Create/Deploy MicroDeployments Enriching Test ClassesRun Tests Inside/Against Container IDE Friendly 30
  62. 62. Integration TestsArquillian brings tests to runtime ks Manage Lifecycle of Container c Apache License 2.0 o M Classes Create/Deploy MicroDeployments o r e Enriching Test o M NRun Tests Inside/Against Container IDE Friendly 30
  63. 63. Integration tests 31
  64. 64. Integration tests 31
  65. 65. Integration tests 31
  66. 66. Integration tests 31
  67. 67. Integration tests 31
  68. 68. Integration tests 31
  69. 69. Demo 32
  70. 70. Acceptance Tests Test Customer Requirements 33
  71. 71. Acceptance Tests User Story everyday language sentence adds business values 34
  72. 72. Acceptance Tests User Story everyday language sentence adds business values As administrator, I want to add new books to a collection, so users can borrow them 34
  73. 73. Acceptance Tests Acceptance Criteria story completeness 35
  74. 74. Acceptance Tests Acceptance Criteria story completenessAdministrator can add new books.Administrator can categorise books.User can borrow books added by administrator. 35
  75. 75. Acceptance Tests Concrete Examples1. Create Lord of the RingsBook.2. Assign J.R.R Tolkien asauthor.3. Set Book Description.4. Add Book to System.5. Check that Book is shownin screen. 36
  76. 76. Acceptance Tests 37
  77. 77. Acceptance Tests JEE UI is Web How to access to web elements 37
  78. 78. Acceptance Tests JEE UI is Web How to access to web elements AT categorised by user stories How to organize user stories and specs 37
  79. 79. Acceptance Tests Thucydides Apache License 2.0 38
  80. 80. Acceptance Tests Thucydides Selenium 2 Extension Apache License 2.0 38
  81. 81. Acceptance Tests Thucydides Selenium 2 Extension Apache License 2.0 Organise tests and stories 38
  82. 82. Acceptance Tests Thucydides Selenium 2 Extension Apache License 2.0 Organise tests and stories Record/Report test execution 38
  83. 83. Acceptance Tests Thucydides Selenium 2 Extension Apache License 2.0 Organise tests and stories Record/Report test execution Measure Functional Cover 38
  84. 84. Acceptance Tests Choose a user story 39
  85. 85. Acceptance Tests Choose a user story Implement PageObject/s 39
  86. 86. Acceptance Tests Choose a user story Implement PageObject/s Implement Test Step Library 39
  87. 87. Acceptance Tests Choose a user story Implement PageObject/s Implement Test Step Library Implement User Story following A.C 39
  88. 88. Demo 40
  89. 89. Continuous Integration Different Kind of Tests Exist 41
  90. 90. Continuous Integration Different Kind of Tests Exist Only Unit tests are run by developers 41
  91. 91. Continuous Integration Different Kind of Tests Exist Only Unit tests are run by developers Continuous Integration System 41
  92. 92. Continuous Integration Provides CI services Build Jobs are Tasks MIT License 42
  93. 93. Continuous Integration Build Pipeline Plugin 43
  94. 94. Continuous Integration Build Pipeline Plugin Create chains of build jobs. 43
  95. 95. Continuous Integration Build Pipeline Plugin Create chains of build jobs. 43
  96. 96. Last Note No Time No Tests 44
  97. 97. Last Note No Time No Tests Fix an error during Production Time 44
  98. 98. Last Note No Time No Tests Fix an error during Production Time Continuous Delivery 44
  99. 99. Thanks 45
  100. 100. Questions Questions ?How many nights I prayed for this, to let my work begin First we take Manhattan, then we take Berlin - Leonard Cohen 46
  101. 101. Questions Questions ? Alex Soto Bueno asotobu@gmail.com www.lordofthejars.com @alexsotobHow many nights I prayed for this, to let my work begin First we take Manhattan, then we take Berlin - Leonard Cohen 46
  102. 102. Creditshttp://www.flickr.com/photos/55182004@N04/5518854399/sizes/o/in/photostream/http://www.flickr.com/photos/wildlifewanderer/6133286089/sizes/o/in/photostream/http://www.flickr.com/photos/luccawithcheese/3180399980/sizes/o/in/photostream/http://www.flickr.com/photos/wildlifewanderer/6133286089/sizes/o/in/photostream/http://www.flickr.com/photos/joachim_s_mueller/6913623388/sizes/o/in/photostream/http://www.flickr.com/photos/dieselpower83/7078627097/sizes/o/in/pool-62802336@N00/http://www.flickr.com/photos/soyignatius/2476388983/sizes/o/in/photostream/http://www.flickr.com/photos/flatbushgardener/440319534/http://www.flickr.com/photos/justinwkern/3597152639/http://www.flickr.com/photos/tolgasoran/5154570906/http://www.flickr.com/photos/pennuja/5363515039/http://www.flickr.com/photos/350org/5069209808/sizes/o/in/photostream/http://www.flickr.com/photos/lliurealbir/3484066523/sizes/o/in/photostream/http://www.flickr.com/photos/windsordi/3467758700/sizes/o/in/photostream/ 47
  103. 103. How to Test Enterprise Java ApplicationsAlex Soto BuenoComputer Engineer

×