SlideShare uma empresa Scribd logo
1 de 12
Baixar para ler offline
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

Mais conteúdo relacionado

Semelhante a How To Tidy Up Your Test Code

Selenium Design Patterns
Selenium Design PatternsSelenium Design Patterns
Selenium Design PatternsLiraz 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
 
The Testing Planet Issue 2
The Testing Planet Issue 2The Testing Planet Issue 2
The Testing Planet Issue 2Rosie Sherry
 
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.org
 
Code coverage & tools
Code coverage & toolsCode coverage & tools
Code coverage & toolsRajesh Kumar
 
Code Review
Code ReviewCode Review
Code ReviewRavi Raj
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestableRoyKlein
 
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 TestingCameron 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.pdfOprim 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 TestingCatherine 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 DevelopersKatalon Studio
 

Semelhante a 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
 

Mais de 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 sideRock 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 CAREERRock 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 lockdownRock 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 alertsRock 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 blowRock 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 isolationRock 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 & AnalyticsRock 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 2020Rock Interview
 
Unusual Interview Questions
Unusual Interview QuestionsUnusual Interview Questions
Unusual Interview QuestionsRock 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 QuestionsRock Interview
 
Machine Learning Interview Questions
Machine Learning Interview QuestionsMachine Learning Interview Questions
Machine Learning Interview QuestionsRock Interview
 
Five Mistakes Beginner Devops Professionals Make
Five Mistakes Beginner Devops Professionals MakeFive Mistakes Beginner Devops Professionals Make
Five Mistakes Beginner Devops Professionals MakeRock Interview
 
Top Technology Trends and Related Jobs
Top Technology Trends and Related JobsTop Technology Trends and Related Jobs
Top Technology Trends and Related JobsRock 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 careerRock 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 MoneyRock Interview
 
Secrets Of High Performing Agile Teams
Secrets Of High Performing Agile TeamsSecrets Of High Performing Agile Teams
Secrets Of High Performing Agile TeamsRock Interview
 
Unit Testing vs Integration Testing
Unit Testing vs Integration TestingUnit Testing vs Integration Testing
Unit Testing vs Integration TestingRock Interview
 

Mais de 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
 

Último

%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 

Último (20)

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

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.