SlideShare a Scribd company logo
Workshop
SPOCK: Testing (in the) Enterprise!
Fernando Redondo Ramírez
@pronoide_fer
Roadmap
Roadmap
Roadmap
Roadmap
Roadmap
How do I start with Gradle?
• Who am I
• …
• Hands on!
• Who am I
• …
• Hands on!
Hands on!
Before start, you have to…
1. Start Groovy/Grails Tool Suite 3.6 (GGTS) and create a workspace (remember run
it with a JDK and install the gradle extension for eclipse). Groovy 2.4 compiler as
well.
2. Download http://pronoide.com/downloads/greach-workshop-2015.zip
and unzip it into workspace folder. Or take it from
https://github.com/fredondo/greach2015-spock-workshop
3. Hold on! Please wait me right here…
Stage I: Import the workshop project
i. Import gradle Project (enterprise.mission)
Specifications
- Test classes are named Specifications
- All specifications (Specs) must extend from
spock.lang.Specification
- Each specification must have at least ONE test
method, all of these are called feature methods
- The most simple assert within a feature method is the
expect block, all its sentences must be evaluated to
true so that the feature will be OK
Specifications
- A very simple specification
Stage II: Creating Specs
Complete the following specification and acomplish the challenges
(org.startrek.challenges.n01.RacesSpec)
Stage II: Creating Specs
Did you get it right?
(org.startrek.solutions.n01.RacesSpec)
Stage II: Creating Specs
• Run the spec class as JUnit test
• Or execute the test gradle task (gradle quick task launcher)
Specfication methods
- Within any specification we can found
- Feature methods (or test methods) with diferent
blocks of code for stating the scenario under spec
- Fixture methods that will be called automatically
before or after any single feature methods or before
and after the specification:
- setup, cleanup, setupSpec and cleanupSpeck
- Helper methods that can be called at any time from
other methods and can be convenient for code clarity
and code reuse
Stage III: Inside the Specs
Complete the following specification and acomplish the challenge
(org.startrek.challenges.n02.VoyageSpec)
Stage III: Inside the Specs
This is not rocket science (org.startrek.solutions.n02.VoyageSpec)
Whoami
• Entrepreneur and Business Manager at
Pronoide since 2003
• Currently working for Hybris (SAP) as technical
trainer
• Java & Friends Trainer
• Doing things with Java from 1999 on
• Computer Engineer
• Happily married and proud father of two children
• Not that Trekky (Sure!)
Stage IV: Inside the feature
Complete the following feature methods and probe your courage
(org.startrek.challenges.n03.SpaceshipSpec)
Stage IV: Inside the feature
Easy peasy!! (org.startrek.solutions.n03.SpaceshipSpec)
Feature method blocks
- These are the kinds of blocks (continuation):
- when and then blocks always occur together. They describe
a stimulus and the expected response. when blocks can
contain arbitrary code, then blocks are restricted to
conditions, exception conditions, interactions, and variable
definitions (which mean more options available that for
expect blocks). There can be multiples pair ocurrencies
within a feature.
Stage IV: Inside the feature
Fill in the next feature method if you dare!
(org.startrek.challenges.n03.StarfleetSpec)
Stage IV: Inside the feature
It was piece of cake!! (org.startrek.solutions.n03.SpaceshipSpec)
Feature method blocks
- These are the kinds of blocks (cont.):
- A where block always comes last in a feature method, and
cannot be repeated. It is used to write data-driven feature
methods. As a matter of convenience it can be written in
two different ways:
- A row per variable with the << symbol
- A column per variable with | symbol
- A data-drive feature method can be annotated with
@unroll, in that case, the method will be invoked multiple
times with the provider data variables. these can be used in
the method description with placeholders (#). For each
iteration the placeholders are replaced with correct values.
Stage IV: Inside the feature
The thing gets tougher!
(org.startrek.challenges.n03.WeaponsDamageSpec)
Stage IV: Inside the feature
As easy as pie!! (org.startrek.solutions.n03.WeaponsDamageSpec)
Testing exceptions
- In order to deal with specification that
throw or not exceptions, Spock provides the
following exception conditions
- thrown(ExceptionClass) and notThrow(ExceptionClass)
- It’s also possible to get the exception instance, to
access its atributtes:
def ex=thrown()
Stage V: Exception Conditions
Complete these two features
(org.startrek.challenges.n04.DestructionSpec)
Stage V: Exception Conditions
Keep it up! (org.startrek.solutions.n04.DestructionSpec)
Interactions
- Interaction-based testing is a design and testing
technique that focusing more on the behavior of
objects rather than their state, it explores how the
object(s) under spec interact, by way of method
calls, with their collaborators
- We need to mock the collaborator implementations via
def colaborator=Mock(Class) Or Class colaborator=Mock()
– Mocks are usually created using Dynamic Proxies or cglib
– we can track interactions with collaborators within then block:
when:
spock.teletransport()
then:
1 * transporter.use()
Stage VI: Interactions
Write down this feature method
(org.startrek.challenges.n05.ShipManagementSpec)
Stage VI: Interactions
It’s not that complicated, is it?
(org.startrek.solutions.n05. ShipManagementSpec)
Useful stuff
- In daily life Spock use, we usually will make use of:
- Share objects among feature via @Shared class
attributes, other way they won’t share them
– There are two kinds of conditions to validate a feature: Implicit
and Explicit. Implicit conditions appear in expect and then blocks.
To use conditions in other places, you can use assert keyword
– Sometimes feature methods are large or contain duplicated code.
It can make sense to introduce helper methods
– Specifications as Documentation, Spock provides a way to attach
textual descriptions to blocks
When: “everything start”
– You can leverage the use of Hamcrest
Stage VI: Other mechanisms
In the following spec identify with mechanisms are used
(org.startrek.challenges.n06.MoviesSpec)
Stage VI: Other mechanisms
No brainer (org.startrek.solutions.n06. MoviesSpec)
Extensions
- Spock offers lots of functionality for writing specs. But, there
always comes a time when something else is needed. Spock
provides an interception-based extension mechanism.
Extensions are activated by annotations called directives.
These are some directives:
- @Timeout Sets a timeout for execution of a feature or fixture
- @Ignore Ignores a feature method
- @IgnoreRest Ignores all feature methods not carrying this annotation.
@IgnoreIf To ignore a feature method under certain conditions
- @FailsWith Expects a feature method to complete abruptly
- @Requires To execute a feature method under certain conditions
- @Stepwise executes features in the order that they are declared
- @Title and @Narrative To attach a natural-language name to a spec
- @Issue indicates that a feature or spec relates to one or more issues in an
external tracking system
- Many more and you can also create your own ones.
Brief introduction
- Groovy based testing and
specification framework
- Can test anything that runs inside the JVM
(even Java)
- Beautiful and highly expressive specification
language
- Compatible with most IDEs, build tools, and
continuous integration servers (JUnit runner)
Extra ball: Geb!
- Geb is a framework for automatization of
functional web testing. It is based on the
following technologies:
– Groovy Language (and it’s incredible with Spock)
– Selenium WebDriver
– JQuery CSS Content Selector
– Page Object Model
- We have to change add dependencies to our build.gradle:
testCompile 'org.gebish:geb-spock:0.10.0'
testCompile "org.seleniumhq.selenium:selenium-chrome-driver:2.43.1”
We have to configure our driver (automated browser) in
src/test/resources/GebConfig.groovy
Extra ball: Geb!
Create a simple driver configuration & download the driver
(src/test/resources/GebConfig.groovy)
Extra ball: Geb!
Let’s perform a search for apock in memory-alpha.org
(org.startrek.challenges.n07.WebNavigationSpec.groovy)
Extra ball: Geb!
That’s great! But, Can YOU do it in a better way?
Extra ball: Geb!
Let’s keep it simple an reusable! Functional Spec.
(org.startrek.solutions.n07.WebNavigationSpec2.groovy)
Extra ball: Geb!
Let’s keep it simple an reusable! Reusable Page Model.
(org.startrek.solutions.n07. MemoryAlphaPage.groovy and
org.startrek.solutions.n07. MemoryAlphaResultsPage.groovy )
Thanks!
• @pronoide_fer
• https://github.com/fredondo/
• fredondo@pronoide.com
• http://pronoide.com
• http://blog.pronoide.es

More Related Content

What's hot

Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
Frank Appel
 
Automated testing in Python and beyond
Automated testing in Python and beyondAutomated testing in Python and beyond
Automated testing in Python and beyond
dn
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
Eugenio Lentini
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black Hole
Noam Kfir
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
Hong Le Van
 
Cpp Testing Techniques Tips and Tricks - Cpp Europe
Cpp Testing Techniques Tips and Tricks - Cpp EuropeCpp Testing Techniques Tips and Tricks - Cpp Europe
Cpp Testing Techniques Tips and Tricks - Cpp Europe
Clare Macrae
 
Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionAlex Su
 
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина ШафранскаяSolit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранскаяsolit
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
Seb Rose
 
Testing In Java
Testing In JavaTesting In Java
Testing In Java
David Noble
 
Working Effectively with Legacy Code: Lessons in Practice
Working Effectively with Legacy Code: Lessons in PracticeWorking Effectively with Legacy Code: Lessons in Practice
Working Effectively with Legacy Code: Lessons in Practice
Amar Shah
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile Apps
Marcelo Busico
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
alessiopace
 
Exception Handling - Part 1
Exception Handling - Part 1 Exception Handling - Part 1
Exception Handling - Part 1
Hitesh-Java
 
Mockito vs JMockit, battle of the mocking frameworks
Mockito vs JMockit, battle of the mocking frameworksMockito vs JMockit, battle of the mocking frameworks
Mockito vs JMockit, battle of the mocking frameworks
EndranNL
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework
OpenDaylight
 
Applying TDD to Legacy Code
Applying TDD to Legacy CodeApplying TDD to Legacy Code
Applying TDD to Legacy Code
Alexander Goida
 
The Evil Tester's Guide to HTTP proxies Tutorial
The Evil Tester's Guide to HTTP proxies TutorialThe Evil Tester's Guide to HTTP proxies Tutorial
The Evil Tester's Guide to HTTP proxies Tutorial
Alan Richardson
 
JMockit
JMockitJMockit
JMockit
Angad Rajput
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
Mike Lively
 

What's hot (20)

Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
Automated testing in Python and beyond
Automated testing in Python and beyondAutomated testing in Python and beyond
Automated testing in Python and beyond
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black Hole
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 
Cpp Testing Techniques Tips and Tricks - Cpp Europe
Cpp Testing Techniques Tips and Tricks - Cpp EuropeCpp Testing Techniques Tips and Tricks - Cpp Europe
Cpp Testing Techniques Tips and Tricks - Cpp Europe
 
Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage Introduction
 
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина ШафранскаяSolit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
 
Testing In Java
Testing In JavaTesting In Java
Testing In Java
 
Working Effectively with Legacy Code: Lessons in Practice
Working Effectively with Legacy Code: Lessons in PracticeWorking Effectively with Legacy Code: Lessons in Practice
Working Effectively with Legacy Code: Lessons in Practice
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile Apps
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 
Exception Handling - Part 1
Exception Handling - Part 1 Exception Handling - Part 1
Exception Handling - Part 1
 
Mockito vs JMockit, battle of the mocking frameworks
Mockito vs JMockit, battle of the mocking frameworksMockito vs JMockit, battle of the mocking frameworks
Mockito vs JMockit, battle of the mocking frameworks
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework
 
Applying TDD to Legacy Code
Applying TDD to Legacy CodeApplying TDD to Legacy Code
Applying TDD to Legacy Code
 
The Evil Tester's Guide to HTTP proxies Tutorial
The Evil Tester's Guide to HTTP proxies TutorialThe Evil Tester's Guide to HTTP proxies Tutorial
The Evil Tester's Guide to HTTP proxies Tutorial
 
JMockit
JMockitJMockit
JMockit
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 

Viewers also liked

Greach 2014 Sesamestreet Grails2 Workshop
Greach 2014 Sesamestreet Grails2 Workshop Greach 2014 Sesamestreet Grails2 Workshop
Greach 2014 Sesamestreet Grails2 Workshop
Fernando Redondo Ramírez
 
Javacro 2014 SemameStreet Grails 2 Speech
Javacro 2014  SemameStreet Grails 2 SpeechJavacro 2014  SemameStreet Grails 2 Speech
Javacro 2014 SemameStreet Grails 2 Speech
Fernando Redondo Ramírez
 
Log -Analytics con Apache-Flume Elasticsearch HDFS Kibana
 Log -Analytics con Apache-Flume  Elasticsearch HDFS Kibana Log -Analytics con Apache-Flume  Elasticsearch HDFS Kibana
Log -Analytics con Apache-Flume Elasticsearch HDFS Kibana
Felix Rodriguez
 
Codemotion 2015 spock_workshop
Codemotion 2015 spock_workshopCodemotion 2015 spock_workshop
Codemotion 2015 spock_workshop
Fernando Redondo Ramírez
 
Seguridad de las aplicaciones web con Spring Security 3.x
Seguridad de las aplicaciones web con Spring Security 3.xSeguridad de las aplicaciones web con Spring Security 3.x
Seguridad de las aplicaciones web con Spring Security 3.x
Fernando Redondo Ramírez
 
Javacro 2014 Spring Security 3 Speech
Javacro 2014 Spring Security 3 SpeechJavacro 2014 Spring Security 3 Speech
Javacro 2014 Spring Security 3 Speech
Fernando Redondo Ramírez
 
Big Data a traves de una implementación
Big Data a traves de una implementaciónBig Data a traves de una implementación
Big Data a traves de una implementación
Diego Krauthamer
 
Emr hive barcamp 2012
Emr hive   barcamp 2012Emr hive   barcamp 2012
Emr hive barcamp 2012
Ezequiel Golub
 
Redis, base de datos NoSQL clave-valor
Redis, base de datos NoSQL clave-valorRedis, base de datos NoSQL clave-valor
Redis, base de datos NoSQL clave-valor
Alberto Gimeno
 
Big Data en FaceBook
Big Data en FaceBookBig Data en FaceBook
Big Data en FaceBook
Juan Frias
 
Conociendo los servicios adicionales en big data
Conociendo los servicios adicionales en big dataConociendo los servicios adicionales en big data
Conociendo los servicios adicionales en big data
SpanishPASSVC
 
CloudCamp - Big Data – La revolución de los datos
CloudCamp - Big Data – La revolución de los datosCloudCamp - Big Data – La revolución de los datos
CloudCamp - Big Data – La revolución de los datos
John Bulla
 
Postgres como base de datos NoSQL. Codemotion 2015
Postgres como base de datos NoSQL. Codemotion 2015Postgres como base de datos NoSQL. Codemotion 2015
Postgres como base de datos NoSQL. Codemotion 2015
Ruben Gómez García
 
Estudio sobre Spark, Storm, Kafka y Hive
Estudio sobre Spark, Storm, Kafka y HiveEstudio sobre Spark, Storm, Kafka y Hive
Estudio sobre Spark, Storm, Kafka y Hive
Wellness Telecom
 
¿Cómo hacer los objetivos?
¿Cómo hacer los objetivos?¿Cómo hacer los objetivos?
¿Cómo hacer los objetivos?
DIANA MARCELA PADILLA RAMIREZ
 

Viewers also liked (15)

Greach 2014 Sesamestreet Grails2 Workshop
Greach 2014 Sesamestreet Grails2 Workshop Greach 2014 Sesamestreet Grails2 Workshop
Greach 2014 Sesamestreet Grails2 Workshop
 
Javacro 2014 SemameStreet Grails 2 Speech
Javacro 2014  SemameStreet Grails 2 SpeechJavacro 2014  SemameStreet Grails 2 Speech
Javacro 2014 SemameStreet Grails 2 Speech
 
Log -Analytics con Apache-Flume Elasticsearch HDFS Kibana
 Log -Analytics con Apache-Flume  Elasticsearch HDFS Kibana Log -Analytics con Apache-Flume  Elasticsearch HDFS Kibana
Log -Analytics con Apache-Flume Elasticsearch HDFS Kibana
 
Codemotion 2015 spock_workshop
Codemotion 2015 spock_workshopCodemotion 2015 spock_workshop
Codemotion 2015 spock_workshop
 
Seguridad de las aplicaciones web con Spring Security 3.x
Seguridad de las aplicaciones web con Spring Security 3.xSeguridad de las aplicaciones web con Spring Security 3.x
Seguridad de las aplicaciones web con Spring Security 3.x
 
Javacro 2014 Spring Security 3 Speech
Javacro 2014 Spring Security 3 SpeechJavacro 2014 Spring Security 3 Speech
Javacro 2014 Spring Security 3 Speech
 
Big Data a traves de una implementación
Big Data a traves de una implementaciónBig Data a traves de una implementación
Big Data a traves de una implementación
 
Emr hive barcamp 2012
Emr hive   barcamp 2012Emr hive   barcamp 2012
Emr hive barcamp 2012
 
Redis, base de datos NoSQL clave-valor
Redis, base de datos NoSQL clave-valorRedis, base de datos NoSQL clave-valor
Redis, base de datos NoSQL clave-valor
 
Big Data en FaceBook
Big Data en FaceBookBig Data en FaceBook
Big Data en FaceBook
 
Conociendo los servicios adicionales en big data
Conociendo los servicios adicionales en big dataConociendo los servicios adicionales en big data
Conociendo los servicios adicionales en big data
 
CloudCamp - Big Data – La revolución de los datos
CloudCamp - Big Data – La revolución de los datosCloudCamp - Big Data – La revolución de los datos
CloudCamp - Big Data – La revolución de los datos
 
Postgres como base de datos NoSQL. Codemotion 2015
Postgres como base de datos NoSQL. Codemotion 2015Postgres como base de datos NoSQL. Codemotion 2015
Postgres como base de datos NoSQL. Codemotion 2015
 
Estudio sobre Spark, Storm, Kafka y Hive
Estudio sobre Spark, Storm, Kafka y HiveEstudio sobre Spark, Storm, Kafka y Hive
Estudio sobre Spark, Storm, Kafka y Hive
 
¿Cómo hacer los objetivos?
¿Cómo hacer los objetivos?¿Cómo hacer los objetivos?
¿Cómo hacer los objetivos?
 

Similar to Greach 2015 Spock workshop

Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
apoorvams
 
Testing - How Vital and How Easy to use
Testing - How Vital and How Easy to useTesting - How Vital and How Easy to use
Testing - How Vital and How Easy to use
Uma Ghotikar
 
The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9
jClarity
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using ReflectionGanesh Samarthyam
 
Implementing Quality on a Java Project
Implementing Quality on a Java ProjectImplementing Quality on a Java Project
Implementing Quality on a Java Project
Vincent Massol
 
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
Andrzej Jóźwiak
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applications
Yura Nosenko
 
Testing – With Mock Objects
Testing – With Mock ObjectsTesting – With Mock Objects
Testing – With Mock Objects
emmettwalsh
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for Distro
Paul Boos
 
Angular Intermediate
Angular IntermediateAngular Intermediate
Angular Intermediate
LinkMe Srl
 
Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdf
KALAISELVI P
 
Debugging
DebuggingDebugging
Debugging
Olivier Teytaud
 
Hadoop testing workshop - july 2013
Hadoop testing workshop - july 2013Hadoop testing workshop - july 2013
Hadoop testing workshop - july 2013
Ophir Cohen
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@Alex Borsuk
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie
hcderaad
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
Ryan Cuprak
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certification
KadharBashaJ
 
20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris
Johan De Wit
 
Puppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven DevelopmentPuppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven Development
Puppet
 

Similar to Greach 2015 Spock workshop (20)

Spock pres
Spock presSpock pres
Spock pres
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
Testing - How Vital and How Easy to use
Testing - How Vital and How Easy to useTesting - How Vital and How Easy to use
Testing - How Vital and How Easy to use
 
The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
Implementing Quality on a Java Project
Implementing Quality on a Java ProjectImplementing Quality on a Java Project
Implementing Quality on a Java Project
 
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applications
 
Testing – With Mock Objects
Testing – With Mock ObjectsTesting – With Mock Objects
Testing – With Mock Objects
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for Distro
 
Angular Intermediate
Angular IntermediateAngular Intermediate
Angular Intermediate
 
Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdf
 
Debugging
DebuggingDebugging
Debugging
 
Hadoop testing workshop - july 2013
Hadoop testing workshop - july 2013Hadoop testing workshop - july 2013
Hadoop testing workshop - july 2013
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certification
 
20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris
 
Puppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven DevelopmentPuppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven Development
 

Recently uploaded

Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 

Recently uploaded (20)

Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 

Greach 2015 Spock workshop

  • 1. Workshop SPOCK: Testing (in the) Enterprise! Fernando Redondo Ramírez @pronoide_fer
  • 7. How do I start with Gradle?
  • 8. • Who am I • … • Hands on!
  • 9. • Who am I • … • Hands on!
  • 10. Hands on! Before start, you have to… 1. Start Groovy/Grails Tool Suite 3.6 (GGTS) and create a workspace (remember run it with a JDK and install the gradle extension for eclipse). Groovy 2.4 compiler as well. 2. Download http://pronoide.com/downloads/greach-workshop-2015.zip and unzip it into workspace folder. Or take it from https://github.com/fredondo/greach2015-spock-workshop 3. Hold on! Please wait me right here…
  • 11. Stage I: Import the workshop project i. Import gradle Project (enterprise.mission)
  • 12. Specifications - Test classes are named Specifications - All specifications (Specs) must extend from spock.lang.Specification - Each specification must have at least ONE test method, all of these are called feature methods - The most simple assert within a feature method is the expect block, all its sentences must be evaluated to true so that the feature will be OK
  • 13. Specifications - A very simple specification
  • 14. Stage II: Creating Specs Complete the following specification and acomplish the challenges (org.startrek.challenges.n01.RacesSpec)
  • 15. Stage II: Creating Specs Did you get it right? (org.startrek.solutions.n01.RacesSpec)
  • 16. Stage II: Creating Specs • Run the spec class as JUnit test • Or execute the test gradle task (gradle quick task launcher)
  • 17. Specfication methods - Within any specification we can found - Feature methods (or test methods) with diferent blocks of code for stating the scenario under spec - Fixture methods that will be called automatically before or after any single feature methods or before and after the specification: - setup, cleanup, setupSpec and cleanupSpeck - Helper methods that can be called at any time from other methods and can be convenient for code clarity and code reuse
  • 18. Stage III: Inside the Specs Complete the following specification and acomplish the challenge (org.startrek.challenges.n02.VoyageSpec)
  • 19. Stage III: Inside the Specs This is not rocket science (org.startrek.solutions.n02.VoyageSpec)
  • 20. Whoami • Entrepreneur and Business Manager at Pronoide since 2003 • Currently working for Hybris (SAP) as technical trainer • Java & Friends Trainer • Doing things with Java from 1999 on • Computer Engineer • Happily married and proud father of two children • Not that Trekky (Sure!)
  • 21. Stage IV: Inside the feature Complete the following feature methods and probe your courage (org.startrek.challenges.n03.SpaceshipSpec)
  • 22. Stage IV: Inside the feature Easy peasy!! (org.startrek.solutions.n03.SpaceshipSpec)
  • 23. Feature method blocks - These are the kinds of blocks (continuation): - when and then blocks always occur together. They describe a stimulus and the expected response. when blocks can contain arbitrary code, then blocks are restricted to conditions, exception conditions, interactions, and variable definitions (which mean more options available that for expect blocks). There can be multiples pair ocurrencies within a feature.
  • 24. Stage IV: Inside the feature Fill in the next feature method if you dare! (org.startrek.challenges.n03.StarfleetSpec)
  • 25. Stage IV: Inside the feature It was piece of cake!! (org.startrek.solutions.n03.SpaceshipSpec)
  • 26. Feature method blocks - These are the kinds of blocks (cont.): - A where block always comes last in a feature method, and cannot be repeated. It is used to write data-driven feature methods. As a matter of convenience it can be written in two different ways: - A row per variable with the << symbol - A column per variable with | symbol - A data-drive feature method can be annotated with @unroll, in that case, the method will be invoked multiple times with the provider data variables. these can be used in the method description with placeholders (#). For each iteration the placeholders are replaced with correct values.
  • 27. Stage IV: Inside the feature The thing gets tougher! (org.startrek.challenges.n03.WeaponsDamageSpec)
  • 28. Stage IV: Inside the feature As easy as pie!! (org.startrek.solutions.n03.WeaponsDamageSpec)
  • 29. Testing exceptions - In order to deal with specification that throw or not exceptions, Spock provides the following exception conditions - thrown(ExceptionClass) and notThrow(ExceptionClass) - It’s also possible to get the exception instance, to access its atributtes: def ex=thrown()
  • 30. Stage V: Exception Conditions Complete these two features (org.startrek.challenges.n04.DestructionSpec)
  • 31. Stage V: Exception Conditions Keep it up! (org.startrek.solutions.n04.DestructionSpec)
  • 32. Interactions - Interaction-based testing is a design and testing technique that focusing more on the behavior of objects rather than their state, it explores how the object(s) under spec interact, by way of method calls, with their collaborators - We need to mock the collaborator implementations via def colaborator=Mock(Class) Or Class colaborator=Mock() – Mocks are usually created using Dynamic Proxies or cglib – we can track interactions with collaborators within then block: when: spock.teletransport() then: 1 * transporter.use()
  • 33. Stage VI: Interactions Write down this feature method (org.startrek.challenges.n05.ShipManagementSpec)
  • 34. Stage VI: Interactions It’s not that complicated, is it? (org.startrek.solutions.n05. ShipManagementSpec)
  • 35. Useful stuff - In daily life Spock use, we usually will make use of: - Share objects among feature via @Shared class attributes, other way they won’t share them – There are two kinds of conditions to validate a feature: Implicit and Explicit. Implicit conditions appear in expect and then blocks. To use conditions in other places, you can use assert keyword – Sometimes feature methods are large or contain duplicated code. It can make sense to introduce helper methods – Specifications as Documentation, Spock provides a way to attach textual descriptions to blocks When: “everything start” – You can leverage the use of Hamcrest
  • 36. Stage VI: Other mechanisms In the following spec identify with mechanisms are used (org.startrek.challenges.n06.MoviesSpec)
  • 37. Stage VI: Other mechanisms No brainer (org.startrek.solutions.n06. MoviesSpec)
  • 38. Extensions - Spock offers lots of functionality for writing specs. But, there always comes a time when something else is needed. Spock provides an interception-based extension mechanism. Extensions are activated by annotations called directives. These are some directives: - @Timeout Sets a timeout for execution of a feature or fixture - @Ignore Ignores a feature method - @IgnoreRest Ignores all feature methods not carrying this annotation. @IgnoreIf To ignore a feature method under certain conditions - @FailsWith Expects a feature method to complete abruptly - @Requires To execute a feature method under certain conditions - @Stepwise executes features in the order that they are declared - @Title and @Narrative To attach a natural-language name to a spec - @Issue indicates that a feature or spec relates to one or more issues in an external tracking system - Many more and you can also create your own ones.
  • 39. Brief introduction - Groovy based testing and specification framework - Can test anything that runs inside the JVM (even Java) - Beautiful and highly expressive specification language - Compatible with most IDEs, build tools, and continuous integration servers (JUnit runner)
  • 40. Extra ball: Geb! - Geb is a framework for automatization of functional web testing. It is based on the following technologies: – Groovy Language (and it’s incredible with Spock) – Selenium WebDriver – JQuery CSS Content Selector – Page Object Model - We have to change add dependencies to our build.gradle: testCompile 'org.gebish:geb-spock:0.10.0' testCompile "org.seleniumhq.selenium:selenium-chrome-driver:2.43.1” We have to configure our driver (automated browser) in src/test/resources/GebConfig.groovy
  • 41. Extra ball: Geb! Create a simple driver configuration & download the driver (src/test/resources/GebConfig.groovy)
  • 42. Extra ball: Geb! Let’s perform a search for apock in memory-alpha.org (org.startrek.challenges.n07.WebNavigationSpec.groovy)
  • 43. Extra ball: Geb! That’s great! But, Can YOU do it in a better way?
  • 44. Extra ball: Geb! Let’s keep it simple an reusable! Functional Spec. (org.startrek.solutions.n07.WebNavigationSpec2.groovy)
  • 45. Extra ball: Geb! Let’s keep it simple an reusable! Reusable Page Model. (org.startrek.solutions.n07. MemoryAlphaPage.groovy and org.startrek.solutions.n07. MemoryAlphaResultsPage.groovy )
  • 46. Thanks! • @pronoide_fer • https://github.com/fredondo/ • fredondo@pronoide.com • http://pronoide.com • http://blog.pronoide.es