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.

What's that smell? Tidying Up our Test Code by Angie Jones

93 views

Published on

We are often reminded by those experienced in writing test automation that code is code. The sentiment being conveyed is that test code should be written with the same care and rigor with which production code is written.

However, many people who write test code may not have experience writing production code, so it’s not exactly clear what is meant by this sentiment. And even those who write production code find that there are unique design patterns and code smells that are specific to test code in which they are not aware.

Given a smelly test automation code base that is littered with several bad coding practices, Angie walks through each of the smells, discusses why it is considered a violation, and demonstrates a cleaner approach by refactoring the code live on stage.

Key takeaways include how to identify code smells within test code, understanding the reasons why an approach is considered problematic, and how to implement clean coding practices within test automation

Published in: Software
  • Be the first to comment

  • Be the first to like this

What's that smell? Tidying Up our Test Code by Angie Jones

  1. 1. What's That Smell?What's That Smell? Angie JonesAngie Jones http://angiejones.techhttp://angiejones.tech http://TestAutomationU.comhttp://TestAutomationU.com @techgirl1908@techgirl1908 Senior Developer AdvocateSenior Developer Advocate Director of Test Automation UniversityDirector of Test Automation University Applitools, San Francisco, CA, USAApplitools, San Francisco, CA, USA Tidying Up Our Test CodeTidying Up Our Test Code
  2. 2. @techgirl1
  3. 3. aa CODE SMELLCODE SMELL is an implementation thatis an implementation that violates fundamental designviolates fundamental design principles in a way that mayprinciples in a way that may slow down development andslow down development and increase the risk of future issues.increase the risk of future issues.
  4. 4. APPLICATIONAPPLICATION UNDERUNDER TESTTEST @techgirl1908
  5. 5. JAKE'SJAKE'S CODECODE BASEBASE @techgirl1908
  6. 6. @techgirl1908 LONG CLASSLONG CLASS � � � The purpose of the class isThe purpose of the class is multifold.multifold. To find anything, you mustTo find anything, you must scroll and scroll.scroll and scroll.
  7. 7. ISSUESISSUES @techgirl1908 1. No single responsibility1. No single responsibility 2. Hard to find things2. Hard to find things 3. Difficult to maintain3. Difficult to maintain
  8. 8. @techgir �� SEPARATESEPARATE CONCERNSCONCERNS �
  9. 9. @techgirl1908 LONG METHODLONG METHOD � � � This guy does it all!This guy does it all! But it makes it hard to knowBut it makes it hard to know when to call.when to call.
  10. 10. ISSUESISSUES @techgirl1908 1. No single responsibility1. No single responsibility 2. Confusing for callers2. Confusing for callers 3. Difficult to read and understan3. Difficult to read and understan
  11. 11. @techgirl1908 WE HAVE A PROBLEM!WE HAVE A PROBLEM! � How come our second testHow come our second test cannot utilize the searchcannot utilize the search method?method?
  12. 12. @techgir �� SPLITSPLIT METHODSMETHODS �
  13. 13. @techgirl1908 DUPLICATE CODEDUPLICATE CODE � � � � When you find yourselfWhen you find yourself coding in haste,coding in haste, it's very temptingit's very tempting to copy and paste.to copy and paste.
  14. 14. ISSUESISSUES @techgirl1908 1. Any change needed has to1. Any change needed has to take place in multiple spotstake place in multiple spots 2. Can lead to other smells2. Can lead to other smells
  15. 15. @techgir �� REMOVEREMOVE DUPLICATIONDUPLICATION �
  16. 16. FLAKY LOCATOR STRATEGYFLAKY LOCATOR STRATEGY � � � � At this moment,At this moment, your locators work fine.your locators work fine. But can theyBut can they stand the test of time?stand the test of time?
  17. 17. ISSUESISSUES @techgirl1908 1. Fragility1. Fragility 2. Unreliability2. Unreliability
  18. 18. @techgir �� STABILIZESTABILIZE LOCATORSLOCATORS �
  19. 19. @techgirl1908 INDECENT EXPOSUREINDECENT EXPOSURE Too many see you.Too many see you. Your scope is too wide.Your scope is too wide. All who should know youAll who should know you
  20. 20. ISSUESISSUES 1. Violates encapsulation1. Violates encapsulation 2. Allows tests to directly access2. Allows tests to directly access and manipulate the DOM,and manipulate the DOM, which is not their responsibilitywhich is not their responsibility
  21. 21. @techgir �� NARROWNARROW SCOPESCOPE �
  22. 22. @techgirl1908 INEFFICIENT WAITSINEFFICIENT WAITS � � � � The speed of machineThe speed of machine is faster than manis faster than man so you slow it downso you slow it down any way you can.any way you can.
  23. 23. ISSUESISSUES @techgirl1908 1. Slows down runtime1. Slows down runtime 2. Different environments may2. Different environments may require different wait timesrequire different wait times
  24. 24. @techgir �� WAITWAIT INTELLIGENTLYINTELLIGENTLY �
  25. 25. @techgirl1908 MULTIPLE POINTS OF FAILUREMULTIPLE POINTS OF FAILURE � � � � The framework's jobThe framework's job is to force state,is to force state, not to determinenot to determine a test's fate.a test's fate.
  26. 26. ISSUESISSUES @techgirl1908 1. Violates single responsibility1. Violates single responsibility 2. Limits reusuability2. Limits reusuability
  27. 27. @techgir �� INCREASEINCREASE FLEXIBILITYFLEXIBILITY �
  28. 28. QUESTIONS?QUESTIONS? @techgirl1908
  29. 29. What's That Smell?What's That Smell? Angie JonesAngie Jones http://angiejones.techhttp://angiejones.tech http://TestAutomationU.comhttp://TestAutomationU.com @techgirl1908@techgirl1908 Senior Developer AdvocateSenior Developer Advocate Director of Test Automation UniversityDirector of Test Automation University Applitools, San Francisco, CA, USAApplitools, San Francisco, CA, USA Tidying Up Our Test CodeTidying Up Our Test Code

×