Slides from my talk on "Rewrite Vs Refactor" given at Agile India 2021. https://confengine.com/conferences/agile-india-2021/proposal/15495/rewrite-vs-refactor
In this session, I will share various examples and experiences and as a result of being in such situations, the factors I looked at when enhancing the code-base to decide - should I refactor or rewrite the code-under-consideration to be able to move forward faster, while moving towards the long-term vision.
Though I will focus on various examples of Test Automation, this session is applicable for any role that writes / maintains code of any nature.
12. • Revamp Testing Quality Practices
• Automate everything that makes sense to automate!
@BagmarAnand
Evolved Charter
https://storage.needpix.com/rsynced_images/smile-2352472_1280.png
14. • Fast feedback (from 1000s of automated UI tests)
• Clarity of intent – know what is being tested
• Maintainable & Scalable Automation
@BagmarAnand
Charter
https://i.pinimg.com/474x/ec/8a/17/ec8a176036490a3338f806172a23e4b3.jpg
16. @BagmarAnand
Assessment: Finding
• Automation code quality is sub-par
• Excessive duplication, massive files, no encapsulation
• Excessive use of “sleep”
• Extremely complex code
• No test execution trend analysis
• Too much focus on UI / end-2-end automation
• No idea what is being tested (without reading a lot of code)
17. • Fast feedback (from 1000s of automated UI tests)
• Clarity of intent – know what is being tested
• Maintainable & Scalable Automation
• Focus on automating tests at lower level
• Unit Test Automation
• API / Component Test Automation
• API Workflow Automation
@BagmarAnand
Evolved Charter
https://storage.needpix.com/rsynced_images/smile-2352472_1280.png
20. package HelloWorld;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
@BagmarAnand
Hello World
54. When you find where
change needs to happen,
then…
@BagmarAnand
55. @BagmarAnand
What is the impact of change going to be?
http://textbook.stpauls.br/Business_Organization/images/pic311.jpg
56. Pressure of getting it done
on Time!
https://newsatjama.files.wordpress.com/2018/07/hourglass-clock-on-light-blue-background-thinkstockphotos-479876312.jpg?w=1200
https://miro.medium.com/max/5600/1*frbsX4eY4Sj2mla2vszKPA.jpeg
@BagmarAnand
60. @BagmarAnand
Anti-pattern: Reinvent the wheel
https://external-preview.redd.it/ZVPjiFo_Ubl4JeiU63SaTjdIoq5zveSnNZimKpgn2I8.png?auto=webp&s=bf32c94b630befa121075c1ae99b2599af6dedc5
• Don’t want to modify existing code
61. @BagmarAnand
Anti-pattern: Reinvent the wheel
https://storage.needpix.com/rsynced_images/traveller-3213992_1280.jpg
• Unable to find what you were looking for
63. @BagmarAnand
Anti-pattern: Sleep to reduce flakiness
https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Zzz_sleep.svg/1024px-Zzz_sleep.svg.png
https://upload.wikimedia.org/wikipedia/commons/thumb/7/76/Evil_red.svg/1200px-Evil_red.svg.png
https://storage.needpix.com/rsynced_images/snail-2383080_1280.jpg
64. Why do we end up using
these anti-patters?
@BagmarAnand
65. Because …. It (still) works!
https://www.linkedin.com/posts/bhagyaitrecruiteratgmail_activity-6642620864221274112-NnWI
@BagmarAnand
66. @BagmarAnand
Let someone else figure out a better way… later
https://lh3.googleusercontent.com/proxy/MuzrRuna5ts_O-FX_KPUcsC-2SA_blkGTlwPUBfLS9uWo11NN5RLhI8dUBucVrGUtTvQs5FP-AGlBrLTXI0VnZzBT0C30E7HvWtOHyqd8TP3QIeJCg
74. @BagmarAnand
Automation does not provide enough value!
https://4.bp.blogspot.com/-dgoCWivfsb8/XDcqaFvQC2I/AAAAAAAAF2o/qz5zcKCf9lcD6ExCo3p16YsFCwkQsCxjgCLcBGAs/s1600/DRC-falling-robot.png
• Difficult to add new features / tests
• Difficult to scale
• Supposedly simple changes take long time, and have
unexpected behavior
80. @BagmarAnand
Overall challenges from Testing perspective
• Process / Way of Working & Ownership of Testing
• Understanding of Automation
• Experience & Skillset
• Coding skills
• Time pressure
• CI
81. • Device & Driver management
• Run on demand, on QA machine
• Slow (100s of sleeps)
• Static methods, no-OOPS
• Sequential
• Branching nightmare!
@BagmarAnand
Reality of existing Automated Tests
https://i.stack.imgur.com/SDmtn.png
88. How to turn the ship
around in such cases?
@BagmarAnand
https://upload.wikimedia.org/wikipedia/commons/7/72/Container_ship_Reecon_Whale_on_Black_Sea_near_Constan%C8%9Ba_Romania.jpg
90. @BagmarAnand
How do we achieve our objectives?
https://www.expandgh.com/wp-content/uploads/2018/04/Set-Objectives-for-Each-Person.jpg
91. @BagmarAnand
How do we achieve our objectives?
https://www.expandgh.com/wp-content/uploads/2018/04/Set-Objectives-for-Each-Person.jpg
Know your objectives first!
92. • Fast in execution and feedback
• Independent tests
• Executed on every change
• Know what is being tested, as the customer / consumer
• Able to release with confidence!
@BagmarAnand
Expectations from Automated Tests
93. @BagmarAnand
Approach
• Increase awareness
• Upskill (pairing, training)
• Evolved way-of-working
• In initial stages, you may want to consider Automation
rewrite as a separate, independent project
94. @BagmarAnand
Approach - Automation
• Identify Design Patterns that will help
• Setup Coding guidelines and coding styles
• Use powerful IDEs
• Automate Infrastructure setup for test execution
• Keep Tests Independent
98. @BagmarAnand
Criteria for Implementing Automation
• Clear & visible intent of the automated test
• Multi-browser & multi-device support
• Run on every (local & deployed) change (local, CI & cloud)
• Fast feedback (parallel execution)
• Rich execution reports & Trend Analysis
• https://www.infoq.com/articles/test-automation-ai-ml/
100. Will team be able to refactor,
while other projects are going on,
and get value from automation,
the way it is supposed to be?
@BagmarAnand
https://lh3.googleusercontent.com/proxy/3JFWJGTlmTym_g9xCZpHIFNLN3rQZu3js8f7iJDHFc6CCeTDb4hpLJaaQm1YCe2BfxyuA_7Lv3B4Clt7MpICbe_Ay09TY8k
104. @BagmarAnand
Approach for Rewrite with Reuse …
• Formed team of 2 people initially
• Automated test execution environment setup script
• Created new repository
• Implemented 2 tests
• Parallel execution
• Triggered automatically via CI
• No manual setup / intervention
105. @BagmarAnand
Approach for Rewrite with Reuse
• Used tools / frameworks / libraries that can achieve the
objectives of the test
• Build Vs Buy / Reuse
• Hard discussions around duplication Vs complexity of
specific modules – ex: test data setup for product
• Rewrite everything, or reuse some existing
implementation?
107. • IDEs provide you lot of information about the code
automatically
• Additional plugins can be installed / used
• Free / Open-Source plugins may also be available
• Static Code Analysis can be setup in VCS / CI pipelines
@BagmarAnand
Maintain Code Quality