SlideShare a Scribd company logo
Is Groovy Better For
Testing Than Java?
Trisha Gee (@trisha_gee)
Developer Advocate, JetBrains
Is Groovy better for testing than Java?
TDD
Test Driven Development Design
Acceptance, Integration, System,
Performance, Unit Tests
Shared understanding & pair
programming
Is Groovy better for testing than Java?
Open source
Downloadable library
The most used driver
The oldest driver
About to be re-written
But the tests were…
Ugly
Inconsistent
Hard to understand
“Test second”
Tightly tied to implementation
Functional / integration
Testing more than one thing
Mostly “happy path”
Not helpful for understanding
the system’s expected behaviour
On the plus side…
The project does have tests
…but no coherent approach to
testing
The tests should:
Be readable
Be easy to write
Describe the expected behaviour
of the system
Possible solutions
•EasyMock / Mockito / JMock
•Home-grown mocking/stubbing
•Standards / Examples
•DSL – Domain Specific Language
•Hamcrest matchers
•Spock
A week to spike Spock
•Questions to answer:
• Is it fast enough to learn that a week can give noticeable
progress?
• Is using Groovy to test Java too big a context switch?
• What benefits does it give us over our current tests?
• What benefits does it give us over the alternatives?
• Will it help developers write “better” tests?
• Does is make the tests more understandable?
Intro to Spock & Groovy
•DBCollectionFunctionalSpecification
• 'should update multiple documents‘
• 'drop index should error if index does not exist‘
•JMXConnectionPoolListenerSpecification
• 'should create a valid ObjectName for ipv4 addresses'
The old tests were ugly
•MongoClientURITest
•-> MongoClientURISpecification
Mocking should be easy
•IterableCodecTest
•-> IterableCodecSpecification
Stubbing should also be easy
•DBCursorFunctionalSpecification
• 'should use provided decoder factory‘
Hamcrest makes testing easier
•DBCollectionFunctionalSpecification
• 'should return a list of all the values of a given field
without duplicates‘
The gains are not always that big
•DBCursorOldTest.testTailableImplicitAwaitOnHas
NextOriginal
•->DBCursorFunctionalSpecification
• 'should block and wait for new documents when cursor is
tailable'
Answers
•Is it fast enough to learn that a week can give
noticeable progress?
• Yes.
• And if in doubt, write Java
Answers
•Is using Groovy to test Java too big a context
switch?
• No. Although you’ll want the new Map syntax in prod
code
Answers
•What benefits does it give us over our current
tests?
• Readability, structure, mocking, stubbing, data driven
testing
Answers
•What benefits does it give us over the
alternatives?
• Mocking and stubbing are very easy and very readable
• A DSL or DSL-style could be introduced via Groovy
• You can still make use of Hamcrest Matchers
Answers
•Will it help developers write “better” tests?
• Yes
Answers
•Does is make the tests more understandable?
• Yes
So which is best, Groovy or
Java?
Lines of Code
Ease of Understanding
Ease of Writing
Performance
Fast Feedback
IDE Support
Ease of Learning (for Java devs)
Ease of Learning (for other devs)
Other Advantages
•Shows how the library can be used from Groovy
•Allows us to learn a new language without
impacting production
•Can just write Java
Other Disadvantages
•Requires investment in learning to get full
advantages
•Some context switching
•We now have (at least) two different ways to test
our code
•…and a possible migration task
Conclusion
•Groovy & Spock are:
• Easy to read and understand
• Easy to write
• Easy to learn
•Java and JUnit are:
• Well understood standards
• Type safe and performant
• Better supported by IDEs
http://bit.ly/GroovyVsJava
Resources
@trisha_gee

More Related Content

What's hot (20)

PPTX
Continuous Integration: Finding problems soonest
Shawn Jones
 
PDF
Four Stages of Automated Testing by Bradley Temple
QA or the Highway
 
PPTX
Code Review
Mikalai Alimenkou
 
PPTX
Clean code - Getting your R&D on board
Ruth Sperer
 
ODP
@LinkingNote annotation in YATSPEC
Wojciech Bulaty
 
PDF
АНТОН МУЖАЙЛО «Test Team Development and Management Techniques»
QADay
 
PDF
АННА ТИМОФІЄВА & СЕРГІЙ МАЛИНОВСЬКИЙ «Tools and Tips of video connection test...
QADay
 
PPTX
OSS Java Analysis - What You Might Be Missing
Coverity
 
PPTX
Writing Better Tests - Applying Clean-Code TDD at 99designs
lachlandonald
 
PDF
Selenium Users Anonymous
Dave Haeffner
 
PDF
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Jason Tice
 
PPTX
Unit testing
Adam Birr
 
PPTX
Code Review Best Practices
Trisha Gee
 
PPTX
Adopting Agile
Coverity
 
PDF
Test Driven Development (TDD) & Continuous Integration (CI)
Fatkul Amri
 
PPTX
Introduction to Test Driven Development
Sarah Dutkiewicz
 
PPTX
Roy Osherove TDD From Scratch
Roy Osherove
 
PPTX
Understanding Why Testing is Importaint
Sana Nasar
 
KEY
Driving application development through behavior driven development
Einar Ingebrigtsen
 
PDF
What would Jesus Developer do?
Lukáš Čech
 
Continuous Integration: Finding problems soonest
Shawn Jones
 
Four Stages of Automated Testing by Bradley Temple
QA or the Highway
 
Code Review
Mikalai Alimenkou
 
Clean code - Getting your R&D on board
Ruth Sperer
 
@LinkingNote annotation in YATSPEC
Wojciech Bulaty
 
АНТОН МУЖАЙЛО «Test Team Development and Management Techniques»
QADay
 
АННА ТИМОФІЄВА & СЕРГІЙ МАЛИНОВСЬКИЙ «Tools and Tips of video connection test...
QADay
 
OSS Java Analysis - What You Might Be Missing
Coverity
 
Writing Better Tests - Applying Clean-Code TDD at 99designs
lachlandonald
 
Selenium Users Anonymous
Dave Haeffner
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Jason Tice
 
Unit testing
Adam Birr
 
Code Review Best Practices
Trisha Gee
 
Adopting Agile
Coverity
 
Test Driven Development (TDD) & Continuous Integration (CI)
Fatkul Amri
 
Introduction to Test Driven Development
Sarah Dutkiewicz
 
Roy Osherove TDD From Scratch
Roy Osherove
 
Understanding Why Testing is Importaint
Sana Nasar
 
Driving application development through behavior driven development
Einar Ingebrigtsen
 
What would Jesus Developer do?
Lukáš Čech
 

Viewers also liked (10)

PDF
Cucumber on the JVM with Groovy
Richard Paul
 
PDF
Staying Ahead of the Curve
Trisha Gee
 
PDF
TDD and BDD in Java 8 - what's in it for me?
John Ferguson Smart Limited
 
PPTX
What Mr. Spock would possibly say about modern unit testing: pragmatic and em...
Yaroslav Yermilov
 
PPTX
Introduction to TDD and Mocking
saeed shargi ghazani
 
PDF
RSpec & TDD Tutorial
Wen-Tien Chang
 
PPTX
Frame switcher library
Roman Khachko
 
PDF
Java SE 8 library design
Stephen Colebourne
 
PDF
BDD Anti-patterns
John Ferguson Smart Limited
 
PDF
Java SE 8 best practices
Stephen Colebourne
 
Cucumber on the JVM with Groovy
Richard Paul
 
Staying Ahead of the Curve
Trisha Gee
 
TDD and BDD in Java 8 - what's in it for me?
John Ferguson Smart Limited
 
What Mr. Spock would possibly say about modern unit testing: pragmatic and em...
Yaroslav Yermilov
 
Introduction to TDD and Mocking
saeed shargi ghazani
 
RSpec & TDD Tutorial
Wen-Tien Chang
 
Frame switcher library
Roman Khachko
 
Java SE 8 library design
Stephen Colebourne
 
BDD Anti-patterns
John Ferguson Smart Limited
 
Java SE 8 best practices
Stephen Colebourne
 
Ad

Similar to Is Groovy better for testing than Java? (20)

PDF
Oscon Java Testing on the Fast Lane
Andres Almiray
 
PPT
Spock Framework
Леонид Ставила
 
PDF
Groovy Testing Sep2009
Paul King
 
PDF
Make Your Testing Groovy
Paul King
 
PDF
Unit test-using-spock in Grails
NexThoughts Technologies
 
PPT
Svcc Groovy Testing
Andres Almiray
 
PPT
GTAC Boosting your Testing Productivity with Groovy
Andres Almiray
 
PDF
3 WAYS TO TEST YOUR COLDFUSION API
Gavin Pickin
 
PDF
3 WAYS TO TEST YOUR COLDFUSION API -
Ortus Solutions, Corp
 
PDF
How To Make Your Testing More Groovy
Craig Smith
 
PDF
An Introduction to Groovy for Java Developers
Kostas Saidis
 
PPTX
Testing 101
Noam Barkai
 
PPTX
Unit testing
NexThoughts Technologies
 
ODP
Groovy intro
NexThoughts Technologies
 
PDF
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
Schalk Cronjé
 
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
PPTX
Grails Spock Testing
TO THE NEW | Technology
 
PDF
The Ultimate Guide to Java Testing Frameworks.pdf
Uncodemy
 
PDF
Apache Groovy: the language and the ecosystem
Kostas Saidis
 
PDF
Using the Groovy Ecosystem for Rapid JVM Development
Schalk Cronjé
 
Oscon Java Testing on the Fast Lane
Andres Almiray
 
Groovy Testing Sep2009
Paul King
 
Make Your Testing Groovy
Paul King
 
Unit test-using-spock in Grails
NexThoughts Technologies
 
Svcc Groovy Testing
Andres Almiray
 
GTAC Boosting your Testing Productivity with Groovy
Andres Almiray
 
3 WAYS TO TEST YOUR COLDFUSION API
Gavin Pickin
 
3 WAYS TO TEST YOUR COLDFUSION API -
Ortus Solutions, Corp
 
How To Make Your Testing More Groovy
Craig Smith
 
An Introduction to Groovy for Java Developers
Kostas Saidis
 
Testing 101
Noam Barkai
 
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
Schalk Cronjé
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
Grails Spock Testing
TO THE NEW | Technology
 
The Ultimate Guide to Java Testing Frameworks.pdf
Uncodemy
 
Apache Groovy: the language and the ecosystem
Kostas Saidis
 
Using the Groovy Ecosystem for Rapid JVM Development
Schalk Cronjé
 
Ad

More from Trisha Gee (20)

PPTX
Career Advice for Architects
Trisha Gee
 
PPTX
Is boilerplate code really so bad?
Trisha Gee
 
PDF
Career Advice for Programmers - ProgNET London
Trisha Gee
 
PDF
Is Boilerplate Code Really So Bad?
Trisha Gee
 
PPTX
Real World Java 9 - JetBrains Webinar
Trisha Gee
 
PDF
Real World Java 9
Trisha Gee
 
PPTX
Real World Java 9
Trisha Gee
 
PPTX
Career Advice for Programmers
Trisha Gee
 
PPTX
Real World Java 9
Trisha Gee
 
PDF
Real World Java 9 (QCon London)
Trisha Gee
 
PPTX
Java 9 Functionality and Tooling
Trisha Gee
 
PDF
Java 8 and 9 in Anger
Trisha Gee
 
PDF
Refactoring to Java 8 (Devoxx BE)
Trisha Gee
 
PDF
Refactoring to Java 8 (QCon New York)
Trisha Gee
 
PDF
Refactoring to Java 8 (Devoxx UK)
Trisha Gee
 
PDF
Java 8 in Anger (JavaOne)
Trisha Gee
 
PPTX
Staying Ahead of the Curve
Trisha Gee
 
PDF
Java 8 in Anger, Devoxx France
Trisha Gee
 
PPTX
Speaker Clinic (Novice Speakers)
Trisha Gee
 
PDF
Java 8 in Anger (QCon London)
Trisha Gee
 
Career Advice for Architects
Trisha Gee
 
Is boilerplate code really so bad?
Trisha Gee
 
Career Advice for Programmers - ProgNET London
Trisha Gee
 
Is Boilerplate Code Really So Bad?
Trisha Gee
 
Real World Java 9 - JetBrains Webinar
Trisha Gee
 
Real World Java 9
Trisha Gee
 
Real World Java 9
Trisha Gee
 
Career Advice for Programmers
Trisha Gee
 
Real World Java 9
Trisha Gee
 
Real World Java 9 (QCon London)
Trisha Gee
 
Java 9 Functionality and Tooling
Trisha Gee
 
Java 8 and 9 in Anger
Trisha Gee
 
Refactoring to Java 8 (Devoxx BE)
Trisha Gee
 
Refactoring to Java 8 (QCon New York)
Trisha Gee
 
Refactoring to Java 8 (Devoxx UK)
Trisha Gee
 
Java 8 in Anger (JavaOne)
Trisha Gee
 
Staying Ahead of the Curve
Trisha Gee
 
Java 8 in Anger, Devoxx France
Trisha Gee
 
Speaker Clinic (Novice Speakers)
Trisha Gee
 
Java 8 in Anger (QCon London)
Trisha Gee
 

Recently uploaded (20)

PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Digital Circuits, important subject in CS
contactparinay1
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 

Is Groovy better for testing than Java?

Editor's Notes

  • #2: Who’s using IntelliJ IDEA? …for groovy? Who’s using Groovy? Who’s heard of Spock? Who’s using Spock?
  • #3: Mentioned in this morning’s talk about reactive frameworks
  • #5: Had a CI environment for running the full suite in 40 minutes Failed Fast
  • #17: “Test second” Tightly tied to implementation Functional/integration tests Often testing more than one thing Mostly “happy path”
  • #19: Functional/integration tests Often testing more than one thing Mostly “happy path”
  • #24: We do see the need of having tests We encourage contributors to write tests for their code We require tests for code review We have a team of experienced Java developers
  • #25: Have a coherent… well, any… approach to testing Have any unit (i.e. fast) tests Have examples of good tests Know what the current tests really cover
  • #27: And easy to understand
  • #28: So developers write them! Preferably writing GOOD tests
  • #42: Given/when/then encourages developers to think about what they’re really testing Easy mocking and stubbing means it’s much easier to write unit tests Data driven testing makes it really easy to add edge cases, unhappy paths, what-ifs
  • #43: Nice syntax for working with Maps Pretty ways of creating Lists String method names Given/when/then gives clear structure Groovy’s nice features for Strings Using closures reduces boilerplate Overall, even when nasty test-too-many-things tests are ported with a straight conversion, Spock’s conventions and Groovy’s boilerplate removal already make it more understandable
  • #45: Groovy: Reduced boilerplate, specifically for Strings, Maps, Lists and inner classes Dynamic language means we only care about types when we really care Advantages of Spock: Mocking is easy and readable, and requires far fewer dependencies Stubbing is similarly painless Data Driven Testing is fantastic for testing many inputs vs output Disadv: Spock requires lines for given/when/then Advantages of Java: If we tested using Java 8 we get some reduced boilerplate Disadvantages of Java Boilerplate is better off hidden behind builders and utils No lovely syntax for Collections Creating Strings is ugly
  • #46: Groovy: Reduced boilerplate, specifically for Strings, Maps, Lists and inner classes Dynamic language means we only care about types when we really care Advantages of Spock: Forced structure Mocking is readable Stubbing is similarly painless Data Driven Testing is fantastic for testing many inputs vs output Testing of Exceptions is much more comprehensive Given/when/then helps developers understand what’s going on when reading Strings as method names aids understanding Advantages of Java: Type safety: you can see what things are immediately More familiar for Java developers to read Disadvantages of Java Too easy to clutter up tests with boilerplate Too easy to write badly structured tests No lovely syntax for Collections
  • #47: Groovy: Reduced boilerplate, specifically for Strings, Maps, Lists and inner classes Dynamic language means we only care about types when we really care Advantages of Spock: Forced structure Mocking is easy and requires far fewer dependencies Stubbing is similarly painless (but takes a bit of practice) Both of these means it’s easier to write fast unit tests Data Driven Testing is fantastic for testing many inputs vs output Testing of Exceptions is much more comprehensive Given/when/then helps developers structure the code when writing… Disadvantages of Spock/Groovy: Learning Curve Advantages of Java: Type safety: failures can be caught before running Type safety: refactoring is automagic More familiar for Java developers to write IDE support and autocomplete makes it easy to write stuff Disadvantages of Java No inherent structure to encourage good tests Requires more discipline to write “better” tests Unwieldy to work with collections Creating Strings is ugly
  • #48: Disadvantages of Groovy: Slower to run individual tests Less predictable (should be able to overcome with better tests) Advantages of Java: Faster (more importantly, more predictable) to run Disadvantages of Java If you’re not using Java 8, using some of the concurrency tools is verbose
  • #49: Disadvantages of Groovy: Slower to run individual tests Slow feedback on simple errors (runtime instead of compile time) Advantages of Spock: Given/when/then gets you thinking up front about how valuable your tests are Advantages of Java: Type safety: failures can be caught before running
  • #50: Groovy: Improving support Even dynamically typed objects have suggestions Disadvantages of Groovy: Refactoring is still not as good as Java Harder to do Test Driven Development Advantages of Spock: Syntax highlighting Advantages of Java: Type safety: failures can be caught before running Type safety: refactoring is automagic
  • #51: Advantages of Java: More familiar for Java developers to write and read
  • #52: Advantages of Java: More familiar for Java developers to write and read
  • #55: Groovy and Spock make it really easy to encourage developers to write tests And to write GOOD tests Java and Junit are FAST, fast to run, fast to write, fast to get feedback Well integrated with the IDE, better for writing tests first