SlideShare a Scribd company logo
HOW TO TIDY UP
YOUR TEST CODE
rockinterview.in
The need for a quality test code
Developers put a lot of rigor into creating good code
structure in terms of naming conventions for classes
and methods, putting them in right packages, grouping
them correctly and adopting good processes.
Although most often ignored, clean code rules can
similarly be applied to test code as well.
There are some tell-tale signs that your test code is
not as solid as you want it to be.
Your test code is messy.
You are not sure about which part of the code
does what.
Your builds are failing.
You fear making any changes to the code lest the
change breaks something else.
Code Smells litter test code
A code smell is an implementation
that violates fundamental design
principles in a way that may slow
down development and increase
the risk of future bugs.
7 WAYS TO TIDY
YOUR TEST CODE
rockinterview.in
Classes are longer
For execution of automated test, the code needs to open your application in a
browser, perform the necessary actions on the application, and then verify the
resulting state of the application.
These are distinct responsibilities and should not be together within a single class.
This is a code smell which makes it difficult to understand what is contained within the
class, which can lead to redundancy and maintenance challenges.
To clean this smell, separate each of these responsibilities in separate classes. This
can make it easier to locate the code, spot redundancy and simplify maintenance.
rockinterview.in
Methods are longer
Similar to long class smell, the long method smell occurs where a method or function
has too many responsibilities.
Challenges with readability, redundancy and maintenance are also common here.
While starting out most methods are small, but over time it grows and becomes
complex. This makes testing difficult while calling the method.
The solution for this is similar to the long-class smell. Separate the concerns, but this
time into individual methods with a single focus.
rockinterview.in
Code Duplication
While doing test automation, it’s common to come across the same piece of code
over and over. Repeating the same logic multiple times in various places is a case of
code smell.
If there is a change within the application within this flow, you will again have to find all
the places where this logic is duplicated within your test code and update each one.
This is time consuming and poses the risk of introducing a bug in the code.
To address this, you can abstract out the common code into their own methods. With
this, the code exists only in one common place, can be easily updated when
required, and can be called by methods that require it.
rockinterview.in
Flaky Locator Strategy
To make UI automation work, you need to provide your tool with identifiers to the
elements that you’d like it to find and interact with. Use of flaky locators that are not
durable is also an awful code smell.
Flaky locators are typically ones provided by a browser in the form of a “Copy Xpath”
option or something similar. The resulting locator is usually one with a long ancestry
tree and indices.
While it might be easy to make this work at the time of capture, it is extremely fragile
and susceptible to any changes made to the page structure. It is a leading cause of
false negative test results.
To fix this, make use of reliable locators such as id or name. For cases where more is
needed – such as with CSS selectors or XPath – craft your elements locator with care.
rockinterview.in
Exposing the code internals
Classes and methods should not expose the internal working of the code. It is
important to hide internal framework code from test layer.
It is a code smell to expose class fields such as web elements used in Page Object
classes, or class methods that return web elements.
To get rid of this smell, narrow the scope of your framework code by adjusting the
access modifiers. Make all necessary class fields private or protected, and do the
same for methods that return web elements.
rockinterview.in
Inefficient waits
In automated code, we have to often introduce pauses or waits to the test code. As
the automated code works faster, slowing the code down provides the
much-needed time for the application under test to process an action.
However, introducing a hard-coded wait that tells the test to pause for x number of
seconds is a code smell. It slows down the overall test execution time and different
environments may require different wait times.
To resist this smell, consider using conditional waiting techniques. Several browser
automation libraries, such as Selenium WebDriver, have methods of providing
responsible ways to wait for certain conditions to occur before continuing with
execution.
rockinterview.in
Multiple Points of Failure
To ensure that the classes are focused on their responsibility and nothing more, test
code is separated from the framework.
Adding assertions within your framework code is a code smell. The code’s
responsibility is not to determine the fate of a test. By doing so, it limits the
reusability of the framework code for both negative and positive scenarios.
To avoid this smell, remove all assertions from your framework code. Allow your test
code to query your framework code for state, and then make the judgement call of
pass or fail within the test itself.
How To Tidy Up Your Test Code
How To Tidy Up Your Test Code

More Related Content

Similar to How To Tidy Up Your Test Code

TestDrivenDeveloment
TestDrivenDevelomentTestDrivenDeveloment
TestDrivenDeveloment
Antonio Tapper
 
Selenium Design Patterns
Selenium Design PatternsSelenium Design Patterns
Selenium Design Patterns
Liraz Shay
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
rupeshchanchal
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
Alex Borsuk
 
Testing Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksTesting Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation Frameworks
Łukasz Morawski
 
Code review
Code reviewCode review
Code review
Abhishek Sur
 
Software coding and testing
Software coding and testingSoftware coding and testing
Software coding and testing
Sandeep Kumar Nayak
 
The Testing Planet Issue 2
The Testing Planet Issue 2The Testing Planet Issue 2
The Testing Planet Issue 2
Rosie Sherry
 
Put to the Test
Put to the TestPut to the Test
Put to the Test
Kevlin Henney
 
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Abdelkrim Boujraf
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
DevDay Da Nang
 
Code coverage & tools
Code coverage & toolsCode coverage & tools
Code coverage & tools
Rajesh Kumar
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
michael.labriola
 
Code Review
Code ReviewCode Review
Code Review
Ravi Raj
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestable
RoyKlein
 
Mule testing
Mule testingMule testing
Mule testing
Shanky Gupta
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
Cameron Presley
 
9 Tips to write efficient and scalable code.pdf
9 Tips to write efficient and scalable code.pdf9 Tips to write efficient and scalable code.pdf
9 Tips to write efficient and scalable code.pdf
Oprim Solutions
 
Best 8 Practices to Ensure Quality Assurance (QA) in Software Testing
Best 8 Practices to Ensure Quality Assurance (QA) in Software TestingBest 8 Practices to Ensure Quality Assurance (QA) in Software Testing
Best 8 Practices to Ensure Quality Assurance (QA) in Software Testing
Catherine William
 
Katalon Studio - Successful Test Automation for both Testers and Developers
Katalon Studio - Successful Test Automation for both Testers and DevelopersKatalon Studio - Successful Test Automation for both Testers and Developers
Katalon Studio - Successful Test Automation for both Testers and Developers
Katalon Studio
 

Similar to How To Tidy Up Your Test Code (20)

TestDrivenDeveloment
TestDrivenDevelomentTestDrivenDeveloment
TestDrivenDeveloment
 
Selenium Design Patterns
Selenium Design PatternsSelenium Design Patterns
Selenium Design Patterns
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Testing Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksTesting Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation Frameworks
 
Code review
Code reviewCode review
Code review
 
Software coding and testing
Software coding and testingSoftware coding and testing
Software coding and testing
 
The Testing Planet Issue 2
The Testing Planet Issue 2The Testing Planet Issue 2
The Testing Planet Issue 2
 
Put to the Test
Put to the TestPut to the Test
Put to the Test
 
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
 
Code coverage & tools
Code coverage & toolsCode coverage & tools
Code coverage & tools
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
Code Review
Code ReviewCode Review
Code Review
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestable
 
Mule testing
Mule testingMule testing
Mule testing
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
 
9 Tips to write efficient and scalable code.pdf
9 Tips to write efficient and scalable code.pdf9 Tips to write efficient and scalable code.pdf
9 Tips to write efficient and scalable code.pdf
 
Best 8 Practices to Ensure Quality Assurance (QA) in Software Testing
Best 8 Practices to Ensure Quality Assurance (QA) in Software TestingBest 8 Practices to Ensure Quality Assurance (QA) in Software Testing
Best 8 Practices to Ensure Quality Assurance (QA) in Software Testing
 
Katalon Studio - Successful Test Automation for both Testers and Developers
Katalon Studio - Successful Test Automation for both Testers and DevelopersKatalon Studio - Successful Test Automation for both Testers and Developers
Katalon Studio - Successful Test Automation for both Testers and Developers
 

More from Rock Interview

Rock Interview Has The Best Solution For You Job Needs
Rock Interview Has The Best Solution For You Job Needs Rock Interview Has The Best Solution For You Job Needs
Rock Interview Has The Best Solution For You Job Needs
Rock Interview
 
Secure your career with Rock Interview by your side
Secure your career with Rock Interview by your sideSecure your career with Rock Interview by your side
Secure your career with Rock Interview by your side
Rock Interview
 
UPSKILL OR RESKILL TO SECURE YOUR CAREER
UPSKILL OR RESKILL TO SECURE YOUR CAREERUPSKILL OR RESKILL TO SECURE YOUR CAREER
UPSKILL OR RESKILL TO SECURE YOUR CAREER
Rock Interview
 
Our guide to a successful job hunt during lockdown
Our guide to a successful job hunt during lockdownOur guide to a successful job hunt during lockdown
Our guide to a successful job hunt during lockdown
Rock Interview
 
A guide to stay away from fake job alerts
A guide to stay away from fake job alertsA guide to stay away from fake job alerts
A guide to stay away from fake job alerts
Rock Interview
 
How to steer clear of the Recession blow
How to steer clear of the Recession blowHow to steer clear of the Recession blow
How to steer clear of the Recession blow
Rock Interview
 
A simple guide to get you through isolation
A simple guide to get you through isolationA simple guide to get you through isolation
A simple guide to get you through isolation
Rock Interview
 
Cloudy With A Chance For Freelancing For a career in Big Data & Analytics
Cloudy With A Chance For Freelancing For a career in Big Data & AnalyticsCloudy With A Chance For Freelancing For a career in Big Data & Analytics
Cloudy With A Chance For Freelancing For a career in Big Data & Analytics
Rock Interview
 
Top Strategic Tech Trend Predictions For 2020
Top Strategic Tech Trend Predictions For 2020Top Strategic Tech Trend Predictions For 2020
Top Strategic Tech Trend Predictions For 2020
Rock Interview
 
Unusual Interview Questions
Unusual Interview QuestionsUnusual Interview Questions
Unusual Interview Questions
Rock Interview
 
Top Soft Skills Employers Are Looking For
Top Soft Skills Employers Are Looking For Top Soft Skills Employers Are Looking For
Top Soft Skills Employers Are Looking For
Rock Interview
 
Full Stack Developer Interview Questions
Full Stack Developer Interview QuestionsFull Stack Developer Interview Questions
Full Stack Developer Interview Questions
Rock Interview
 
Machine Learning Interview Questions
Machine Learning Interview QuestionsMachine Learning Interview Questions
Machine Learning Interview Questions
Rock Interview
 
Five Mistakes Beginner Devops Professionals Make
Five Mistakes Beginner Devops Professionals MakeFive Mistakes Beginner Devops Professionals Make
Five Mistakes Beginner Devops Professionals Make
Rock Interview
 
Top Technology Trends and Related Jobs
Top Technology Trends and Related JobsTop Technology Trends and Related Jobs
Top Technology Trends and Related Jobs
Rock Interview
 
The Essentials Of Test Driven Development
The Essentials Of Test Driven Development The Essentials Of Test Driven Development
The Essentials Of Test Driven Development
Rock Interview
 
Five Powerful Skills To Boost Programme career
Five Powerful Skills To Boost Programme careerFive Powerful Skills To Boost Programme career
Five Powerful Skills To Boost Programme career
Rock Interview
 
Machine Learning Is Saving Major Sectors Time and Money
Machine Learning Is Saving Major Sectors Time and MoneyMachine Learning Is Saving Major Sectors Time and Money
Machine Learning Is Saving Major Sectors Time and Money
Rock Interview
 
Secrets Of High Performing Agile Teams
Secrets Of High Performing Agile TeamsSecrets Of High Performing Agile Teams
Secrets Of High Performing Agile Teams
Rock Interview
 
Unit Testing vs Integration Testing
Unit Testing vs Integration TestingUnit Testing vs Integration Testing
Unit Testing vs Integration Testing
Rock Interview
 

More from Rock Interview (20)

Rock Interview Has The Best Solution For You Job Needs
Rock Interview Has The Best Solution For You Job Needs Rock Interview Has The Best Solution For You Job Needs
Rock Interview Has The Best Solution For You Job Needs
 
Secure your career with Rock Interview by your side
Secure your career with Rock Interview by your sideSecure your career with Rock Interview by your side
Secure your career with Rock Interview by your side
 
UPSKILL OR RESKILL TO SECURE YOUR CAREER
UPSKILL OR RESKILL TO SECURE YOUR CAREERUPSKILL OR RESKILL TO SECURE YOUR CAREER
UPSKILL OR RESKILL TO SECURE YOUR CAREER
 
Our guide to a successful job hunt during lockdown
Our guide to a successful job hunt during lockdownOur guide to a successful job hunt during lockdown
Our guide to a successful job hunt during lockdown
 
A guide to stay away from fake job alerts
A guide to stay away from fake job alertsA guide to stay away from fake job alerts
A guide to stay away from fake job alerts
 
How to steer clear of the Recession blow
How to steer clear of the Recession blowHow to steer clear of the Recession blow
How to steer clear of the Recession blow
 
A simple guide to get you through isolation
A simple guide to get you through isolationA simple guide to get you through isolation
A simple guide to get you through isolation
 
Cloudy With A Chance For Freelancing For a career in Big Data & Analytics
Cloudy With A Chance For Freelancing For a career in Big Data & AnalyticsCloudy With A Chance For Freelancing For a career in Big Data & Analytics
Cloudy With A Chance For Freelancing For a career in Big Data & Analytics
 
Top Strategic Tech Trend Predictions For 2020
Top Strategic Tech Trend Predictions For 2020Top Strategic Tech Trend Predictions For 2020
Top Strategic Tech Trend Predictions For 2020
 
Unusual Interview Questions
Unusual Interview QuestionsUnusual Interview Questions
Unusual Interview Questions
 
Top Soft Skills Employers Are Looking For
Top Soft Skills Employers Are Looking For Top Soft Skills Employers Are Looking For
Top Soft Skills Employers Are Looking For
 
Full Stack Developer Interview Questions
Full Stack Developer Interview QuestionsFull Stack Developer Interview Questions
Full Stack Developer Interview Questions
 
Machine Learning Interview Questions
Machine Learning Interview QuestionsMachine Learning Interview Questions
Machine Learning Interview Questions
 
Five Mistakes Beginner Devops Professionals Make
Five Mistakes Beginner Devops Professionals MakeFive Mistakes Beginner Devops Professionals Make
Five Mistakes Beginner Devops Professionals Make
 
Top Technology Trends and Related Jobs
Top Technology Trends and Related JobsTop Technology Trends and Related Jobs
Top Technology Trends and Related Jobs
 
The Essentials Of Test Driven Development
The Essentials Of Test Driven Development The Essentials Of Test Driven Development
The Essentials Of Test Driven Development
 
Five Powerful Skills To Boost Programme career
Five Powerful Skills To Boost Programme careerFive Powerful Skills To Boost Programme career
Five Powerful Skills To Boost Programme career
 
Machine Learning Is Saving Major Sectors Time and Money
Machine Learning Is Saving Major Sectors Time and MoneyMachine Learning Is Saving Major Sectors Time and Money
Machine Learning Is Saving Major Sectors Time and Money
 
Secrets Of High Performing Agile Teams
Secrets Of High Performing Agile TeamsSecrets Of High Performing Agile Teams
Secrets Of High Performing Agile Teams
 
Unit Testing vs Integration Testing
Unit Testing vs Integration TestingUnit Testing vs Integration Testing
Unit Testing vs Integration Testing
 

Recently uploaded

Verified Girls Call Mumbai 👀 9820252231 👀 Cash Payment With Room DeliveryDeli...
Verified Girls Call Mumbai 👀 9820252231 👀 Cash Payment With Room DeliveryDeli...Verified Girls Call Mumbai 👀 9820252231 👀 Cash Payment With Room DeliveryDeli...
Verified Girls Call Mumbai 👀 9820252231 👀 Cash Payment With Room DeliveryDeli...
87tomato
 
Il Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazioneIl Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazione
confluent
 
InflectraCON 360: Risk-Based Testing for Mission Critical Systems
InflectraCON 360: Risk-Based Testing for Mission Critical SystemsInflectraCON 360: Risk-Based Testing for Mission Critical Systems
InflectraCON 360: Risk-Based Testing for Mission Critical Systems
Inflectra
 
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
kiara pandey
 
Odoo E-commerce website development guides
Odoo E-commerce website development guidesOdoo E-commerce website development guides
Odoo E-commerce website development guides
jhkdigitalmarketing
 
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
OnePlan Solutions
 
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
singhlata50dh
 
PathSpotter: Exploring Tested Paths to Discover Missing Tests (FSE 2024)
PathSpotter: Exploring Tested Paths to Discover Missing Tests (FSE 2024)PathSpotter: Exploring Tested Paths to Discover Missing Tests (FSE 2024)
PathSpotter: Exploring Tested Paths to Discover Missing Tests (FSE 2024)
andrehoraa
 
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
norina2645
 
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
dream girl
 
當測試開始左移
當測試開始左移當測試開始左移
當測試開始左移
Jersey (CHE-PING) Su
 
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
rachitkumar09887
 
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
bhumivarma35300
 
Fantastic Design Patterns and Where to use them No Notes.pdf
Fantastic Design Patterns and Where to use them No Notes.pdfFantastic Design Patterns and Where to use them No Notes.pdf
Fantastic Design Patterns and Where to use them No Notes.pdf
6m9p7qnjj8
 
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
jealousviolet
 
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
simran hot girls
 
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdfAI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
Daniel Zivkovic
 
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
confluent
 
SEO Cheat Sheet with Learning Resources by Balti Bloggers.pdf
SEO Cheat Sheet with Learning Resources by Balti Bloggers.pdfSEO Cheat Sheet with Learning Resources by Balti Bloggers.pdf
SEO Cheat Sheet with Learning Resources by Balti Bloggers.pdf
Balti Bloggers
 
Russian Girls Call Mumbai 🎈🔥9930687706 🔥💋🎈 Provide Best And Top Girl Service ...
Russian Girls Call Mumbai 🎈🔥9930687706 🔥💋🎈 Provide Best And Top Girl Service ...Russian Girls Call Mumbai 🎈🔥9930687706 🔥💋🎈 Provide Best And Top Girl Service ...
Russian Girls Call Mumbai 🎈🔥9930687706 🔥💋🎈 Provide Best And Top Girl Service ...
shanihomely
 

Recently uploaded (20)

Verified Girls Call Mumbai 👀 9820252231 👀 Cash Payment With Room DeliveryDeli...
Verified Girls Call Mumbai 👀 9820252231 👀 Cash Payment With Room DeliveryDeli...Verified Girls Call Mumbai 👀 9820252231 👀 Cash Payment With Room DeliveryDeli...
Verified Girls Call Mumbai 👀 9820252231 👀 Cash Payment With Room DeliveryDeli...
 
Il Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazioneIl Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazione
 
InflectraCON 360: Risk-Based Testing for Mission Critical Systems
InflectraCON 360: Risk-Based Testing for Mission Critical SystemsInflectraCON 360: Risk-Based Testing for Mission Critical Systems
InflectraCON 360: Risk-Based Testing for Mission Critical Systems
 
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
Celebrity Girls Call Mumbai 9930687706 Unlimited Short Providing Girls Servic...
 
Odoo E-commerce website development guides
Odoo E-commerce website development guidesOdoo E-commerce website development guides
Odoo E-commerce website development guides
 
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
 
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
 
PathSpotter: Exploring Tested Paths to Discover Missing Tests (FSE 2024)
PathSpotter: Exploring Tested Paths to Discover Missing Tests (FSE 2024)PathSpotter: Exploring Tested Paths to Discover Missing Tests (FSE 2024)
PathSpotter: Exploring Tested Paths to Discover Missing Tests (FSE 2024)
 
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
Celebrity Girls Call Mumbai 🛵🚡9910780858 💃 Choose Best And Top Girl Service A...
 
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
 
當測試開始左移
當測試開始左移當測試開始左移
當測試開始左移
 
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
Agra Girls Call Agra 0X0000000X Unlimited Short Providing Girls Service Avail...
 
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
Independent Girls call Service Pune 000XX00000 Provide Best And Top Girl Serv...
 
Fantastic Design Patterns and Where to use them No Notes.pdf
Fantastic Design Patterns and Where to use them No Notes.pdfFantastic Design Patterns and Where to use them No Notes.pdf
Fantastic Design Patterns and Where to use them No Notes.pdf
 
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
 
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
Girls Call Jogeshwari 9967584737 Provide Best And Top Girl Service And No1 in...
 
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdfAI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
 
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
 
SEO Cheat Sheet with Learning Resources by Balti Bloggers.pdf
SEO Cheat Sheet with Learning Resources by Balti Bloggers.pdfSEO Cheat Sheet with Learning Resources by Balti Bloggers.pdf
SEO Cheat Sheet with Learning Resources by Balti Bloggers.pdf
 
Russian Girls Call Mumbai 🎈🔥9930687706 🔥💋🎈 Provide Best And Top Girl Service ...
Russian Girls Call Mumbai 🎈🔥9930687706 🔥💋🎈 Provide Best And Top Girl Service ...Russian Girls Call Mumbai 🎈🔥9930687706 🔥💋🎈 Provide Best And Top Girl Service ...
Russian Girls Call Mumbai 🎈🔥9930687706 🔥💋🎈 Provide Best And Top Girl Service ...
 

How To Tidy Up Your Test Code

  • 1. HOW TO TIDY UP YOUR TEST CODE
  • 2. rockinterview.in The need for a quality test code Developers put a lot of rigor into creating good code structure in terms of naming conventions for classes and methods, putting them in right packages, grouping them correctly and adopting good processes. Although most often ignored, clean code rules can similarly be applied to test code as well. There are some tell-tale signs that your test code is not as solid as you want it to be. Your test code is messy. You are not sure about which part of the code does what. Your builds are failing. You fear making any changes to the code lest the change breaks something else. Code Smells litter test code A code smell is an implementation that violates fundamental design principles in a way that may slow down development and increase the risk of future bugs.
  • 3. 7 WAYS TO TIDY YOUR TEST CODE
  • 4. rockinterview.in Classes are longer For execution of automated test, the code needs to open your application in a browser, perform the necessary actions on the application, and then verify the resulting state of the application. These are distinct responsibilities and should not be together within a single class. This is a code smell which makes it difficult to understand what is contained within the class, which can lead to redundancy and maintenance challenges. To clean this smell, separate each of these responsibilities in separate classes. This can make it easier to locate the code, spot redundancy and simplify maintenance.
  • 5. rockinterview.in Methods are longer Similar to long class smell, the long method smell occurs where a method or function has too many responsibilities. Challenges with readability, redundancy and maintenance are also common here. While starting out most methods are small, but over time it grows and becomes complex. This makes testing difficult while calling the method. The solution for this is similar to the long-class smell. Separate the concerns, but this time into individual methods with a single focus.
  • 6. rockinterview.in Code Duplication While doing test automation, it’s common to come across the same piece of code over and over. Repeating the same logic multiple times in various places is a case of code smell. If there is a change within the application within this flow, you will again have to find all the places where this logic is duplicated within your test code and update each one. This is time consuming and poses the risk of introducing a bug in the code. To address this, you can abstract out the common code into their own methods. With this, the code exists only in one common place, can be easily updated when required, and can be called by methods that require it.
  • 7. rockinterview.in Flaky Locator Strategy To make UI automation work, you need to provide your tool with identifiers to the elements that you’d like it to find and interact with. Use of flaky locators that are not durable is also an awful code smell. Flaky locators are typically ones provided by a browser in the form of a “Copy Xpath” option or something similar. The resulting locator is usually one with a long ancestry tree and indices. While it might be easy to make this work at the time of capture, it is extremely fragile and susceptible to any changes made to the page structure. It is a leading cause of false negative test results. To fix this, make use of reliable locators such as id or name. For cases where more is needed – such as with CSS selectors or XPath – craft your elements locator with care.
  • 8. rockinterview.in Exposing the code internals Classes and methods should not expose the internal working of the code. It is important to hide internal framework code from test layer. It is a code smell to expose class fields such as web elements used in Page Object classes, or class methods that return web elements. To get rid of this smell, narrow the scope of your framework code by adjusting the access modifiers. Make all necessary class fields private or protected, and do the same for methods that return web elements.
  • 9. rockinterview.in Inefficient waits In automated code, we have to often introduce pauses or waits to the test code. As the automated code works faster, slowing the code down provides the much-needed time for the application under test to process an action. However, introducing a hard-coded wait that tells the test to pause for x number of seconds is a code smell. It slows down the overall test execution time and different environments may require different wait times. To resist this smell, consider using conditional waiting techniques. Several browser automation libraries, such as Selenium WebDriver, have methods of providing responsible ways to wait for certain conditions to occur before continuing with execution.
  • 10. rockinterview.in Multiple Points of Failure To ensure that the classes are focused on their responsibility and nothing more, test code is separated from the framework. Adding assertions within your framework code is a code smell. The code’s responsibility is not to determine the fate of a test. By doing so, it limits the reusability of the framework code for both negative and positive scenarios. To avoid this smell, remove all assertions from your framework code. Allow your test code to query your framework code for state, and then make the judgement call of pass or fail within the test itself.