SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
REALIZANDO
PRUEBAS CON
SPOCK
ANDRES ALMIRAY
@AALMIRAY
ANDRESALMIRAY.COM
@aalmiray
@aalmiray
JCP Executive Committee Associate Seat
Committer
Committer
JSR377 Specification Lead
@aalmiray
HTTP://SPOCKFRAMEWORK.ORG/
HTTPS://GITHUB.COM/SPOCKFRAMEWORK
@aalmiray
AGENDA
1.  Conceptos Básicos
2.  Parametrización
3.  Mock/Stub/Spy
4.  Extensiones
@aalmiray
CONCEPTOS
BASICOS
@aalmiray
CONCEPTOS BASICOS - JUNIT
public	class	SampleTest	{	
				@Test	public	void	simpleSpecificationExample()	{	
								//	given:	
								List<String>	list	=	new	ArrayList<>();	
	
								//	when:	
								list.add("Groovy");	
	
								//	then:	
								assertThat(list,	contains("Groovy"));		
				}	
}
@aalmiray
CONCEPTOS BASICOS - SPOCK
public	class	SampleSpec	extends	Specification	{	
				public	void	simpleSpecificationExample()	{	
								given:	
								List<String>	list	=	new	ArrayList<>();	
	
								when:	
								list.add("Groovy");	
	
								then:	
								assert	list.contains("Groovy");	
								assert	list.size()	==	1;	
				}	
}
@aalmiray
CONCEPTOS BASICOS - SPOCK
class	SampleSpec	extends	Specification	{	
				def	"A	simple	Specification	Example"	()	{	
								given:	
								List<String>	list	=	[]	
	
								when:	
								list	<<	'Groovy'	
	
								then:	
								list	==	['Groovy']	
					}	
}
@aalmiray
BLOQUES
given / setup
when
then
expect
where
and
cleanup
@aalmiray
FIXTURE METHODS
def	setup()	{…}	
def	cleanup()	{…}	
def	setupSpec()	{…}	
def	cleanupSpec()	{…}																								Spock	
-----------------------------------------------------	
@Before	public	void	setUp()	{…}														JUnit	
@After	public	void	tearDown()	{…}	
@BeforeClass	public	static	void	setUpTestCase()	{…}	
@AfterClass	public	static	void	tearDownTestCase()	{…}
@aalmiray
PARAMETRIZACION
@aalmiray
PARAMETRIZACION
@Unroll	
class	HelloServiceSpecification	extends	Specification	{	
				def	"Invoking	sayHello('#input')	yields	'#output'"()	{	
								given:	
								HelloService	service	=	new	DefaultHelloService()	
	
								when:	
								String	result	=	service.sayHello(input)	
	
								then:		
								result	==	output	
	
								where:	
								input		<<	['',	'Test']		
								output	<<	['Howdy	stranger!	',	'Hello	Test']	
				}	
}
@aalmiray
PARAMETRIZACION
@Unroll	
class	HelloServiceSpecification	extends	Specification	{	
				def	"Invoking	sayHello('#input')	yields	'#output'"()	{	
								given:	
								HelloService	service	=	new	DefaultHelloService()	
	
								when:	
								String	result	=	service.sayHello(input)	
	
								then:		
								result	==	output	
	
								where:	
								input		|	output	
								''					|	'Howdy	stranger!'	
								'Test'	|	'Hello	Test'	
				}	
}
@aalmiray
MOCK/STUB/SPY
@aalmiray
MOCK + INTERACCIONES
class	SampleSpec	extends	Specification	{	
				def	"A	mocking	example"()	{	
								given:	
								Collaborator	collaborator	=	Mock()	
								1	*	collaborator.foo()	>>	'Spock'	
								Component	component	=	new	Component(collaborator)	
								when:	
								String	output	=	component.doit('is	Groovy!')	
								then:	
								output	==	'Spock	is	Groovy!’	
				}	
}
@aalmiray
CARDINALIDAD
1	*	subscriber.receive("hello")	
0	*	subscriber.receive("hello")	
(1..3)	*	subscriber.receive("hello")	
(1.._)	*	subscriber.receive("hello")	
(_..3)	*	subscriber.receive("hello")	
_	*	subscriber.receive("hello")
@aalmiray
TARGET Y METODO
1	*	subscriber.receive("hello")					
1	*	_.receive("hello")	
1	*	subscriber._("hello")		
1	*	subscriber./r.*e/("hello")	)					
1	*	_._("hello")
@aalmiray
ARGUMENTOS
1	*	subscriber.receive("hello")					
1	*	subscriber.receive(!"hello")				
1	*	subscriber.receive()												
1	*	subscriber.receive(_)											
1	*	subscriber.receive(*_)										
1	*	subscriber.receive(!null)							
1	*	subscriber.receive(_	as	String)	
1	*	subscriber.receive({	it.size()	>	3	})
@aalmiray
ASCII ART?
(_.._)	*	_._(*_)	>>	_
@aalmiray
ASCII ART?
(_.._)	*	_._(*_)	>>	_	
		1						2	3	4						5	
	
1.  Cardinalidad	0	a	infinito	
2.  Cualquier	Mock/Stub/Spy	
3.  Cualquier	método	
4.  0	o	más	argumentos	
5.  Valor	de	retorno	genérico
@aalmiray
EXTENSIONES
@aalmiray
IGNORAR METODOS
•  @Ignore
•  Ignora un solo método
•  @IgnoreRest
•  Ignora los demás métodos
•  @IgnoreIf
•  Ignora un método de manera condicional
@aalmiray
@IGNOREIF
class	SampleSpec	extends	Specification	{	
		@IgnoreIf({System.getBoolean("fast")})	
		def	"A	expensive	data	driven	test"	()	{	
				given:	
				.	.	.		
		}	
}
@aalmiray
@STEPWISE
@Stepwise	
class	BakeACakeSpec	extends	Specification	{	
			def	"Fetch	ingredients"	()	{	.	.	.	}	
			def	"Mix	ingredients"	()	{	.	.	.	}	
			def	"Decorate	bake"	()	{	.	.	.	}	
			def	"Bake	it!"	()	{	.	.	.	}	
			def	"Serve	and	enjoy"	()	{	.	.	.	}	
}
@aalmiray
HTTP://ANDRESALMIRAY.COM/NEWSLETTER
HTTP://ANDRESALMIRAY.COM/EDITORIAL
@aalmiray
@aalmiray
http://www.jespanol.org
GRACIAS!
ANDRES ALMIRAY
@AALMIRAY
ANDRESALMIRAY.COM

Mais conteúdo relacionado

Semelhante a Realizando Pruebas con Spock

CDI do básico ao avançado
CDI do básico ao avançadoCDI do básico ao avançado
CDI do básico ao avançado
Alberto Souza
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
Guillaume Laforge
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 

Semelhante a Realizando Pruebas con Spock (20)

Generating characterization tests for legacy code
Generating characterization tests for legacy codeGenerating characterization tests for legacy code
Generating characterization tests for legacy code
 
CDI do básico ao avançado
CDI do básico ao avançadoCDI do básico ao avançado
CDI do básico ao avançado
 
Java Libraries You Can't Afford To Miss
Java Libraries You Can't Afford To MissJava Libraries You Can't Afford To Miss
Java Libraries You Can't Afford To Miss
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
Java Libraries You Can't Afford to Miss
Java Libraries You Can't Afford to MissJava Libraries You Can't Afford to Miss
Java Libraries You Can't Afford to Miss
 
Spring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergrationSpring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergration
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Canjs
CanjsCanjs
Canjs
 
Testing Java Code Effectively - BaselOne17
Testing Java Code Effectively - BaselOne17Testing Java Code Effectively - BaselOne17
Testing Java Code Effectively - BaselOne17
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
Vulpes tribes backend
Vulpes tribes backendVulpes tribes backend
Vulpes tribes backend
 
No SQL Unit - Devoxx 2012
No SQL Unit - Devoxx 2012No SQL Unit - Devoxx 2012
No SQL Unit - Devoxx 2012
 
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
 
Jersey
JerseyJersey
Jersey
 
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem novaKotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
 
Sequelize
SequelizeSequelize
Sequelize
 
Introduzione al TDD
Introduzione al TDDIntroduzione al TDD
Introduzione al TDD
 

Mais de Andres Almiray

Mais de Andres Almiray (20)

Creando, creciendo, y manteniendo una comunidad de codigo abierto
Creando, creciendo, y manteniendo una comunidad de codigo abiertoCreando, creciendo, y manteniendo una comunidad de codigo abierto
Creando, creciendo, y manteniendo una comunidad de codigo abierto
 
Liberando a produccion con confianza
Liberando a produccion con confianzaLiberando a produccion con confianza
Liberando a produccion con confianza
 
Liberando a produccion con confidencia
Liberando a produccion con confidenciaLiberando a produccion con confidencia
Liberando a produccion con confidencia
 
OracleDB Ecosystem for Java Developers
OracleDB Ecosystem for Java DevelopersOracleDB Ecosystem for Java Developers
OracleDB Ecosystem for Java Developers
 
Softcon.ph - Maven Puzzlers
Softcon.ph - Maven PuzzlersSoftcon.ph - Maven Puzzlers
Softcon.ph - Maven Puzzlers
 
Maven Puzzlers
Maven PuzzlersMaven Puzzlers
Maven Puzzlers
 
Oracle Database Ecosystem for Java Developers
Oracle Database Ecosystem for Java DevelopersOracle Database Ecosystem for Java Developers
Oracle Database Ecosystem for Java Developers
 
JReleaser - Releasing at the speed of light
JReleaser - Releasing at the speed of lightJReleaser - Releasing at the speed of light
JReleaser - Releasing at the speed of light
 
Building modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and LayrryBuilding modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and Layrry
 
Going Reactive with g rpc
Going Reactive with g rpcGoing Reactive with g rpc
Going Reactive with g rpc
 
Building modular applications with JPMS and Layrry
Building modular applications with JPMS and LayrryBuilding modular applications with JPMS and Layrry
Building modular applications with JPMS and Layrry
 
Taking Micronaut out for a spin
Taking Micronaut out for a spinTaking Micronaut out for a spin
Taking Micronaut out for a spin
 
Apache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and YouApache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and You
 
What I wish I knew about Maven years ago
What I wish I knew about Maven years agoWhat I wish I knew about Maven years ago
What I wish I knew about Maven years ago
 
What I wish I knew about maven years ago
What I wish I knew about maven years agoWhat I wish I knew about maven years ago
What I wish I knew about maven years ago
 
The impact of sci fi in tech
The impact of sci fi in techThe impact of sci fi in tech
The impact of sci fi in tech
 
Gradle Ex Machina - Devoxx 2019
Gradle Ex Machina - Devoxx 2019Gradle Ex Machina - Devoxx 2019
Gradle Ex Machina - Devoxx 2019
 
Creating Better Builds with Gradle
Creating Better Builds with GradleCreating Better Builds with Gradle
Creating Better Builds with Gradle
 
Interacting with the Oracle Cloud Java SDK with Gradle
Interacting with the Oracle Cloud Java SDK with GradleInteracting with the Oracle Cloud Java SDK with Gradle
Interacting with the Oracle Cloud Java SDK with Gradle
 
Gradle ex-machina
Gradle ex-machinaGradle ex-machina
Gradle ex-machina
 

Último

Último (20)

The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 

Realizando Pruebas con Spock