Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Increase testability with code seams

2,256 views

Published on

How to turn hard to test code into simple to test code.

Published in: Software
  • Be the first to comment

Increase testability with code seams

  1. 1. Increase Testability with Code Seams @LlewellynFalco
  2. 2. SEAMS
  3. 3. BATTERY TESTING
  4. 4. BATTERY TESTING
  5. 5. Why is Testing Hard? 1. Setup 2. Lot’s of paths 3. Global state 4. Lot’s of clutter 5. Environment 6. Uncontrollable Variables 7. UI 8. Money 9. Dates 10.Mobile 11.Database 12.Integration 13.Wait Times 14.XPath 15.Finding Elements 16.Timing 17.Failure cases
  6. 6. Automated checking is a tactic of testing, and can have considerable value... …Checking through an API beneath the GUI level can be particularly useful. In designing such low-level checks, programmers and testers can profitably work together. We are more doubtful of automated checking at the GUI level. GUIs are notoriously fussy.
  7. 7. CASE #3: Automated checking. We wanted to demonstrate full-on automated checking, while at the same time staying with the FocusWriter example. FocusWriter does not provide an API for testing, which required us to automate through the GUI, and so the headaches began.
  8. 8. TESTING EDIT PROFILE
  9. 9. TESTING EDIT PROFILE
  10. 10. TESTING EDIT PROFILE
  11. 11. BYPASS LOGIN https://github.com/login ?return_to=https://github.com/settings/profile &user_name=isidore &password=Password123
  12. 12. BYPASS EVERYTHING https://github.com/EditProfile/ ?data={“Name”: “Llewellyn Falco”, “photo”:”http://”….}
  13. 13. Testing Pyramid Slow Medium Fast 1-5% 5-15% 80-90%
  14. 14. TESTING EDIT PROFILE By.xpath("//div[@class='canvas- graph']//div[contains(text(),Location)][input]/following-sibling::h4”)
  15. 15. TESTING EDIT PROFILE By.id(”locatation_input”)
  16. 16. DarkFunction Editor Test 1. Open df editor 2. Find File -> Find New -> Find Animation set 3. Navigate to github -> dark function editor -> Testing Resources -> StarWarsImages -> SWAII.sprites 4. Open 5. Add animation 6. Add animation (1) 7. Add animation (2) 8. Rename animation 1 -> animation a 9. add animation 10 . find animation 3 confirm exists.
  17. 17. DarkFunction Unique Name
  18. 18. DarkFunction Unique Name Given animation names: animation, animation 2 When I ask for a new name Then I get animation 3
  19. 19. DarkFunction Editor Test 1. Open df editor 2. Find File -> Find New -> Find Animation set 3. Navigate to github -> dark function editor -> Testing Resources -> StarWarsImages -> SWAII.sprites 4. Open 5. Add animation 6. Add animation (1) 7. Add animation (2) 8. Rename animation 1 -> animation a 9. add animation 10 . find animation 3 confirm exists.
  20. 20. DarkFunction Editor Seams
  21. 21. Functional Deterministic All inputs in All results out
  22. 22. NON-Functional Get inputs as needed (global state, file, database…) Result vary (dates, random, environment) Store results (global, disk, database, transient)
  23. 23. public double calculate(double amount) { int step1 = (int) (amount * 2); double step2 = step1 * 1.5; return step2; } All results out All inputs in Deterministic
  24. 24. public int Advance() { return steps++; } All inputs in?
  25. 25. All inputs in? Deterministic? public int age(DateTime birthDate) { var timeSpan = DateTime.Now - birthDate; var age = DateTime.MinValue + timeSpan; return age.Year-1; }
  26. 26. public void saveFile(Person info, string fileName) { File.WriteAllText(fileName, info.ToString()); } All results out?
  27. 27. WHY FUNCTIONAL IS EASIER FOR TESTS Unit Test Production Code Do Verify
  28. 28. WHY FUNCTIONAL IS EASIER FOR TESTS Unit Test Production Code Do Verify Functional Harness
  29. 29. public static Output function(inputs)
  30. 30. STEPS 1. Determine functional parts 2. Separate 3. Extract 4. Compare against intention
  31. 31. SEPARATING FUNCTIONAL PIECES Non-Functional Functional List
  32. 32. SEPARATING FUNCTIONAL PIECES Non-Functional Functional List List2
  33. 33. PEEL *http://lfal.co/PeelAndSlice
  34. 34. SLICE return sample *http://lfal.co/PeelAndSlice
  35. 35. Why is Testing Hard? 1. XPath 2. Finding Elements 3. Global state 4. Dates 5. Failure cases 6. Wait Times 7. Mobile 8. Setup 9. Lot’s of paths 10.Environment 11.Uncontrollable Variables 12.UI 13.Money 14.Dates 15.Database 16.Integration 17.Finding Elements 18.Timing
  36. 36. Fix: Global State
  37. 37. Resources www.ApprovalTests.com 21 episode youtube series
  38. 38. #MobProgrammingGuidebook
  39. 39. Contact Information @LlewellynFalco http://LlewellynFalco.Blogspot.com http://www.approvaltests.com

×