Spock
A Unit Testing
Framework
Presented By: Deepak Mehra
Senior Software Consultant
Knoldus Inc.
About Knoldus
Knoldus is a technology consulting firm with focus on modernizing the digital systems
at the pace your business demands.
DevOps
Functional. Reactive. Cloud Native
01 What is Spock Framework?
02 Spock Features
03 Why Spock Framework?
04 What is Specification?
05 Mocking and Stubbing
05050505
05
Our Agenda
06 JUnit vs Spock
What is Spock Framework?
● Spock is a BDD-style developer testing and specification framework for Java and
Groovy applications.
● Spock combines unit testing, mocking stubbing and business driven development
all into one framework so you don’t have to download/include additional libraries
in your build.
● Everything is inbuilt in Spock framework, it was inspired by JUnit framework only
and JUnit is also used under the hood.
● We will write the code in Java but we will test the code in Groovy.
Spock Features
● Highly expressive – Test cases can be expressed in terms of given, when and then
blocks.
● Compatible with most IDEs – It is compatible with all the leading IDEs in the
market.
● Compatible with build tools – Compatible with Maven as well as Gradle.
● Compatible with Continuous integration servers – The JUnit runner makes it
compatible with all the continuous integration servers out there.
Why Spock Framework?
● Highly Expressive Specification Language.
● Compatibility with leading IDEs.
● Test cases are written in Groovy which is pretty much similar to Java and also a
JVM based language.
● One framework for all types of test cases, no other libraries are required to write
test cases.
● Expressive than the typical Junit.
● Easy data driven testing which was very verbose in Junit
What is Specification?
● A specification is represented as a Groovy class that extends from
spock.lang.Specification.
● The name of a specification usually relates to the system or system operation
described by the specification.
● Class Specification contains a number of useful methods for writing specifications.
Furthermore it instructs JUnit to run specification with Sputnik, Spock’s JUnit runner.
● Thanks to Sputnik, Spock specifications can be run by most modern Java IDEs and
build tools.
Demo
References
http://spockframework.org
http://webconsole.spockframework.org
https://blog.knoldus.com/introduction-to-spock-a-unit-testing-framework/
https://github.com/deepakmehra10/spock-demo
Thank You!
@deeps_1991
deepak.mehra@knoldus.
com
https://www.linkedin.co
m/in/deepak-mehra-69
478843/

Introduction to Spock: A Unit Testing Framework

  • 1.
    Spock A Unit Testing Framework PresentedBy: Deepak Mehra Senior Software Consultant Knoldus Inc.
  • 2.
    About Knoldus Knoldus isa technology consulting firm with focus on modernizing the digital systems at the pace your business demands. DevOps Functional. Reactive. Cloud Native
  • 3.
    01 What isSpock Framework? 02 Spock Features 03 Why Spock Framework? 04 What is Specification? 05 Mocking and Stubbing 05050505 05 Our Agenda 06 JUnit vs Spock
  • 4.
    What is SpockFramework? ● Spock is a BDD-style developer testing and specification framework for Java and Groovy applications. ● Spock combines unit testing, mocking stubbing and business driven development all into one framework so you don’t have to download/include additional libraries in your build. ● Everything is inbuilt in Spock framework, it was inspired by JUnit framework only and JUnit is also used under the hood. ● We will write the code in Java but we will test the code in Groovy.
  • 5.
    Spock Features ● Highlyexpressive – Test cases can be expressed in terms of given, when and then blocks. ● Compatible with most IDEs – It is compatible with all the leading IDEs in the market. ● Compatible with build tools – Compatible with Maven as well as Gradle. ● Compatible with Continuous integration servers – The JUnit runner makes it compatible with all the continuous integration servers out there.
  • 6.
    Why Spock Framework? ●Highly Expressive Specification Language. ● Compatibility with leading IDEs. ● Test cases are written in Groovy which is pretty much similar to Java and also a JVM based language. ● One framework for all types of test cases, no other libraries are required to write test cases. ● Expressive than the typical Junit. ● Easy data driven testing which was very verbose in Junit
  • 7.
    What is Specification? ●A specification is represented as a Groovy class that extends from spock.lang.Specification. ● The name of a specification usually relates to the system or system operation described by the specification. ● Class Specification contains a number of useful methods for writing specifications. Furthermore it instructs JUnit to run specification with Sputnik, Spock’s JUnit runner. ● Thanks to Sputnik, Spock specifications can be run by most modern Java IDEs and build tools.
  • 8.
  • 9.
  • 10.