SlideShare a Scribd company logo
1 of 19
Download to read offline
TESTAREA
APLICAȚIILOR

RUBY ON RAILS
CU RSPEC
Cezar Hălmăgean
@ c halm age an
Luc rez 	c u	Ruby	on	Rails	&	RSpe c 	din	2007
C ons ultanță	 R uby	 on	 R ails
m ixandgo. com
Ar ticol e	pe	Sem aphore CI,	Ruby	Weekl y,	Blog	(m ixandgo.com /blog)
Idei Principale
Teste	de	funcționalitate	
Orice	funcționalitate	nouă,	începe	cu	un	test	de	funcționalitate	
Teste	de	integrare	
Cazurile	mai	puțin	evidente	sau	vizibile	sunt	acoperite	cu	teste	de	integrare
Teste	unitare	
Intră	în	detaliu	și	testează	toate	cazurile	posibile
De ce să testezi?
Nevoile	de	business	se	schimbă	constant	
Funcționalitate	nouă	vs.	funcționalitate	existentă
Documentație	
Proiectele	mici	devin	mari,	uităm	repede
Upgrade/refactoring	mai	ușor	
Rails,	Ruby,	librării
Mai	puține	bug-uri	
Lucrezi	mai	relaxat,	la	ceva	nou
De ce RSpec?
Ușor	de	ciTt	
TestUnit/MiniTest	vs.	RSpec	
def test_will_return_nil
result = calculate_result
assert_nil result
end
it 'returns nil'
result = calculate_result
expect(result).to be_nil
end
Popularitate	
RSpec	a	devenit	foarte	popular	în	2008	
Comunitate	
E	mai	ușor	să	găseșM	exemple
Cele 3 tipuri de teste
Teste	de	funcționalitate	(UI)	
Testează	doar	ce	poți	vedea	
Teste	de	integrare	(request-uri)	
Testează	doar	ce	nu	poți	vedea
Teste	unitare	(modele,	logica	de	business)	
Testează	izolat	și	cazuri	speciale
System
Controllers
Email
Routes
Jobs
ViewsHelpers
MutaTon
Alte tipuri de teste
Testele de funcționalitate
Testează	doar	ce	poți	vedea	
Formulare,	butoane,	filtrare,	etc.
În	colaborare	cu	clientul	
Ajută	la	stabilirea	obiecMvului/cerințelor
Durează	destul	de	mult	
Scrie	cât	de	puține	poți	și	acoperă	cât	mai	mult
Două	feluri	de	a	le	scrie	
Capybara	și	Cucumber
Capybara
Poate	folosi	un	browser	sau	poate	rula	headless	
Selenium,	poltergeist,	capybara-webkit,	rack-test
ȘTe	să	aștepte	după	evenimente	asincron	
Popup-uri,	ajax,	etc.
RSpec.feature 'Homepage', type: :feature do
scenario 'displays a welcome message' do
visit '/'
expect(page).to have_content 'Welcome'
end
end
Folosește	un	limbaj	mai	neprietenos	
E	ușor	de	ințeles	de	programatori
Cucumber
Te	forțează	să	schimbi	perspecTva	
Să	te	pui	în	locul	clientului	(proprietarul	afacerii)
Poate	folosi	ca	documentație	
E	mai	ușor	de	ciMt	chiar	și	de	programatori
Folosește	un	limbaj	prietenos	(Gherkin)	
E	ușor	de	ințeles	de	non-tehnici
Feature: Homepage
Scenario: Visitor lands on the homepage
When I go to the homepage
Then I should see a welcome message
Cucumber
În	spate	folosește	Capybara	
Este	opțional	dar	îmbunătățește	colaborarea
Se	instalează	separat	de	RSpec	
În	test	environment
group :test do
gem 'cucumber-rails', require: false
gem 'database_cleaner' # multiple threads
end
$ rails generate cucumber:install
Cucumber
Exemple	pași	cucumber	
Folosește	regex	ca	să	găsească	pașii
When(/^I go to the homepage$/) do
visit root_path
end
Then(/^I should see a welcome message$/) do
expect(page).to have_content 'Welcome'
end
bit.ly/codecamp_cucumber
Introduction to Writing Acceptance Tests with Cucumber
Testele de integrare
Testează	doar	ce	NU	poți	vedea	
Email-uri,	baze	de	date,	API-uri,	etc.
Confirmă	că	unitățile	merg	bine	împreună	
Că	se	respectă	contractele	între	obiecte
Durează	puțin	mai	mult	ca	testele	unitare	
E	ok	să	ai	mai	multe	verificări	într-un	singur	test
Nu	trebuie	să	fie	DRY	
Au	rol	de	documentație
Testele de integrare
Exemplu	test	de	integrare	
Nu	folosește	Capybara
RSpec.describe 'Homepage', type: :request do
describe 'GET /' do
it 'renders the homepage' do
get root_path
expect(response.body).to match('Welcome')
end
end
end
Testele unitare
Acoperă	cât	mai	multe	cazuri	
Doar	unitatea	testată,	nu	și	colaboratorii
Acoperă	cazurile	mai	rar	întâlnite	
Fuzz(ing)	/	property-based
Sunt	destul	de	rapide	
Pot	fi	mai	rapide	dacă	le	separi	de	Rails
Două	feluri	de	a	testa	modelele	
Cu	AR	/models	și	fără	AR	/lib
Testele unitare (recomandări)
O	singură	verificare	/	test	
Ca	să	idenMfici	mai	ușor	sursa	erorii
Nu	testa	implementarea	
Doar	rezultatul
Prea	multe	mock-uri	
Indică	o	problemă	de	design
Sincronizează	mock-urile	cu	Verifying	Doubles	
bit.ly/codecamp_vd
Concluzie
Teste	de	funcționalitate	
Testează	doar	ce	POȚI	vedea	
Teste	de	integrare	
Testează	doar	ce	NU	POȚI	vedea
Teste	unitare	
Testează	izolat	și	cazuri	speciale
DEMO
Cezar Hălmăgean
@ c halm age an
m ixandgo. com
TESTAREA APLICAȚIILOR
RUBY ON RAILS CU RSPEC
g it hub. com /c ha lm a ge a n/code ca m p

More Related Content

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Testarea aplicatiilor Ruby on Rails cu RSpec