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
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
What's that smell? Tidying Up our Test Code by Angie Jones
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
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.
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. 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
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. @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?
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. 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
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?
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
23. ISSUESISSUES
@techgirl1908
1. Slows down runtime1. Slows down runtime
2. Different environments may2. Different environments may
require different wait timesrequire different wait times
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.
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