SlideShare a Scribd company logo
TDD in CQ5/AEM
Sagar Sane
What’s on the plate?
● What is Test driven development (TDD)?
● Why TDD / BDD?
● CQ backend and Spock testing framework
● Live code
Not on the plate
● Advanced testing techniques
o Features of Spock Framework
● Much about testing your UI / JS
● Software Consultant II / Tech lead
● WEM Consultant
o Backend development
o Comfortable with Java (/JSP) and Groovy
● I don’t dislike front-end development :-)
About me
I became a programmer because of the
‘science’ in programming,
but, I remained a programmer because of the
‘art’ in programming.
I believe..
Some people have very strong opinions about this...
No, REALLY!
Test Driven Development
● Write Test First (extreme programming)
o Technical meaning
o Design your code around the tests
● Write a lot of tests
o Milder approach
What is a Unit Test in CQ/AEM?
Benefits of Testing
● Find bugs early
● Make it easy for a new person on your
project
o Read the tests if you don’t understand the code
● Improve code quality
Benefits of Testing
● Helps during code re-factoring
● A good test is worth a thousand comments
● Executable documentation
BDD
● Behavior Driven Development
● Writing tests from the customer’s /
stakeholder’s point of view
● It really is TDD done well!
● More expressive than TDD
//Variables
expected, v1, v2, ..
//Execute feature
actual = System.executeFeature(v1, v2, ..)
//The system gives output as expected
assert actual == expected
CQ/AEM and Spock
● What is Spock Framework? [ link ]
● Why is it awesome? [ link ] [ link ]
o Is beautiful
● It can be used to test your CQ/AEM
backend!
A basic Spock Feature
//Spock ‘feature’
def "My component should just work"() {
given:
final variables = [ //initial conditions ]
final expected = new MyComponent(...)
when:
final actual = MyComponent.create(variables)
then:
actual == expected
}
Time for some real code...
What ‘new’ will we see?
● Mocks in spock
● setupSpec(), cleanupSpec()
● @Ignore(), @Shared
What all can you do?
● Unit tests for servlets, services
● Integration tests
● Functional tests for your rest APIs
● Even UI tests! (with Geb)
What all can you do?
Test Automation
Where to go from here?
● Don’t have to start big
● Add tests to the code that is important,
needs change
● Start new implementations with TDD
The art of programming!
Thank you!

More Related Content

What's hot

Yet Another Continuous Integration Story
Yet Another Continuous Integration StoryYet Another Continuous Integration Story
Yet Another Continuous Integration Story
Anton Serdyuk
 
BDD with SpecFlow and Selenium
BDD with SpecFlow and SeleniumBDD with SpecFlow and Selenium
BDD with SpecFlow and Selenium
Liraz Shay
 
Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)
Mindfire Solutions
 
Cucumber BDD
Cucumber BDDCucumber BDD
Cucumber BDD
Pravin Dsilva
 
C# 6
C# 6C# 6
Behat - human-readable automated testing
Behat - human-readable automated testingBehat - human-readable automated testing
Behat - human-readable automated testing
nyccamp
 
BDD with Behat
BDD with BehatBDD with Behat
BDD with Behat
Richard Shank
 
BDD and Behave
BDD and BehaveBDD and Behave
BDD and Behave
Adam Englander
 
HotelQuickly Product & Engineering
HotelQuickly Product & EngineeringHotelQuickly Product & Engineering
HotelQuickly Product & Engineering
Michal Juhas
 
Contributing to open source
Contributing to open sourceContributing to open source
Contributing to open source
Devin Abbott
 
Making cross browser tests beautiful
Making cross browser tests beautifulMaking cross browser tests beautiful
Making cross browser tests beautiful
Meaghan Lewis
 
Selenium + Specflow
Selenium + SpecflowSelenium + Specflow
Selenium + Specflow
cromwellryan
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkin
Arati Joshi
 
Automation test framework with cucumber – BDD
Automation test framework with cucumber – BDDAutomation test framework with cucumber – BDD
Automation test framework with cucumber – BDD
123abcda
 
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Oren Rubin
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
Daniel Kummer
 
What Is Cucumber?
What Is Cucumber?What Is Cucumber?
What Is Cucumber?
QATestLab
 
Behavior Driven GUI Testing
Behavior Driven GUI TestingBehavior Driven GUI Testing
Behavior Driven GUI Testing
Reginald Stadlbauer
 
iOS development best practices
iOS development best practicesiOS development best practices
iOS development best practices
Michal Juhas
 

What's hot (20)

Yet Another Continuous Integration Story
Yet Another Continuous Integration StoryYet Another Continuous Integration Story
Yet Another Continuous Integration Story
 
BDD with SpecFlow and Selenium
BDD with SpecFlow and SeleniumBDD with SpecFlow and Selenium
BDD with SpecFlow and Selenium
 
Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)
 
Cucumber BDD
Cucumber BDDCucumber BDD
Cucumber BDD
 
C# 6
C# 6C# 6
C# 6
 
Behat - human-readable automated testing
Behat - human-readable automated testingBehat - human-readable automated testing
Behat - human-readable automated testing
 
BDD with Behat
BDD with BehatBDD with Behat
BDD with Behat
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
BDD and Behave
BDD and BehaveBDD and Behave
BDD and Behave
 
HotelQuickly Product & Engineering
HotelQuickly Product & EngineeringHotelQuickly Product & Engineering
HotelQuickly Product & Engineering
 
Contributing to open source
Contributing to open sourceContributing to open source
Contributing to open source
 
Making cross browser tests beautiful
Making cross browser tests beautifulMaking cross browser tests beautiful
Making cross browser tests beautiful
 
Selenium + Specflow
Selenium + SpecflowSelenium + Specflow
Selenium + Specflow
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkin
 
Automation test framework with cucumber – BDD
Automation test framework with cucumber – BDDAutomation test framework with cucumber – BDD
Automation test framework with cucumber – BDD
 
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
What Is Cucumber?
What Is Cucumber?What Is Cucumber?
What Is Cucumber?
 
Behavior Driven GUI Testing
Behavior Driven GUI TestingBehavior Driven GUI Testing
Behavior Driven GUI Testing
 
iOS development best practices
iOS development best practicesiOS development best practices
iOS development best practices
 

Similar to Test Driven Development in CQ5/AEM

Effective TDD - Less is more
Effective TDD - Less is moreEffective TDD - Less is more
Effective TDD - Less is moreBen Lau
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
Brett Child
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
Gianluca Padovani
 
Reliable mobile test automation
Reliable mobile test automationReliable mobile test automation
Reliable mobile test automation
Vishal Banthia
 
Testing of React JS app
Testing of React JS appTesting of React JS app
Testing of React JS app
Aleks Zinevych
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
wesovi
 
Test Driven Development with PHP
Test Driven Development with PHPTest Driven Development with PHP
Test Driven Development with PHP
Rogério Vicente
 
TDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and GomegaTDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and Gomega
Eddy Reyes
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
Xavi Hidalgo
 
Getting started with karate dsl
Getting started with karate dslGetting started with karate dsl
Getting started with karate dsl
Knoldus Inc.
 
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowMay 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
Adam Doyle
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
Jon Kruger
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
Test driven development_continuous_integration
Test driven development_continuous_integrationTest driven development_continuous_integration
Test driven development_continuous_integration
haochenglee
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
Pascal Larocque
 
Testing with Express, Mocha & Chai
Testing with Express, Mocha & ChaiTesting with Express, Mocha & Chai
Testing with Express, Mocha & Chai
Joerg Henning
 
How to be proud when you are done
How to be proud when you are doneHow to be proud when you are done
How to be proud when you are done
Mikalai Alimenkou
 
How to be proud when you are done
How to be proud when you are doneHow to be proud when you are done
How to be proud when you are done
Aleksey Solntsev
 

Similar to Test Driven Development in CQ5/AEM (20)

Effective TDD - Less is more
Effective TDD - Less is moreEffective TDD - Less is more
Effective TDD - Less is more
 
UPC Plone Testing Talk
UPC Plone Testing TalkUPC Plone Testing Talk
UPC Plone Testing Talk
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Reliable mobile test automation
Reliable mobile test automationReliable mobile test automation
Reliable mobile test automation
 
Testing of React JS app
Testing of React JS appTesting of React JS app
Testing of React JS app
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
 
Test Driven Development with PHP
Test Driven Development with PHPTest Driven Development with PHP
Test Driven Development with PHP
 
TDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and GomegaTDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and Gomega
 
Spock pres
Spock presSpock pres
Spock pres
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
Getting started with karate dsl
Getting started with karate dslGetting started with karate dsl
Getting started with karate dsl
 
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowMay 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Test driven development_continuous_integration
Test driven development_continuous_integrationTest driven development_continuous_integration
Test driven development_continuous_integration
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
Testing with Express, Mocha & Chai
Testing with Express, Mocha & ChaiTesting with Express, Mocha & Chai
Testing with Express, Mocha & Chai
 
How to be proud when you are done
How to be proud when you are doneHow to be proud when you are done
How to be proud when you are done
 
How to be proud when you are done
How to be proud when you are doneHow to be proud when you are done
How to be proud when you are done
 

Recently uploaded

Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 

Recently uploaded (20)

Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 

Test Driven Development in CQ5/AEM

  • 2. What’s on the plate? ● What is Test driven development (TDD)? ● Why TDD / BDD? ● CQ backend and Spock testing framework ● Live code
  • 3. Not on the plate ● Advanced testing techniques o Features of Spock Framework ● Much about testing your UI / JS
  • 4. ● Software Consultant II / Tech lead ● WEM Consultant o Backend development o Comfortable with Java (/JSP) and Groovy ● I don’t dislike front-end development :-) About me
  • 5. I became a programmer because of the ‘science’ in programming, but, I remained a programmer because of the ‘art’ in programming. I believe..
  • 6. Some people have very strong opinions about this...
  • 8. Test Driven Development ● Write Test First (extreme programming) o Technical meaning o Design your code around the tests ● Write a lot of tests o Milder approach
  • 9. What is a Unit Test in CQ/AEM?
  • 10. Benefits of Testing ● Find bugs early ● Make it easy for a new person on your project o Read the tests if you don’t understand the code ● Improve code quality
  • 11. Benefits of Testing ● Helps during code re-factoring ● A good test is worth a thousand comments ● Executable documentation
  • 12. BDD ● Behavior Driven Development ● Writing tests from the customer’s / stakeholder’s point of view ● It really is TDD done well! ● More expressive than TDD
  • 13. //Variables expected, v1, v2, .. //Execute feature actual = System.executeFeature(v1, v2, ..) //The system gives output as expected assert actual == expected
  • 14.
  • 15. CQ/AEM and Spock ● What is Spock Framework? [ link ] ● Why is it awesome? [ link ] [ link ] o Is beautiful ● It can be used to test your CQ/AEM backend!
  • 16. A basic Spock Feature //Spock ‘feature’ def "My component should just work"() { given: final variables = [ //initial conditions ] final expected = new MyComponent(...) when: final actual = MyComponent.create(variables) then: actual == expected }
  • 17. Time for some real code... What ‘new’ will we see? ● Mocks in spock ● setupSpec(), cleanupSpec() ● @Ignore(), @Shared
  • 18. What all can you do? ● Unit tests for servlets, services ● Integration tests ● Functional tests for your rest APIs ● Even UI tests! (with Geb)
  • 19. What all can you do? Test Automation
  • 20. Where to go from here? ● Don’t have to start big ● Add tests to the code that is important, needs change ● Start new implementations with TDD
  • 21. The art of programming!

Editor's Notes

  1. Hello everyone… Thanks for joining, today we will be talking about Test Driven Development. - Testing during development.
  2. We will discuss about Test Driven Development , Behavior Driven Development. What it is, what are the benefits? Then, try apply our understanding of TDD / BDD to testing our backend code in CQ using Spock Framework ) .. and also look at some code!
  3. .. We will NOT be going into advanced details .. my goal is to get people excited about testing. Hopefully, the testing framework I will be talking about (Spock) will help. We will also be looking at some live code later, going through some basics examples of Spock testing We will not talk about these
  4. I am this.. that.. PAUSE...
  5. So, here is a statement I read somewhere recently I am really starting to believe in the above saying. -- I want to be able to say this for myself in say 10 years for now. But, What does this mean? art? what is the ‘art’ of programming? -- We will try to answer these questions by the time we end the talk today … having said that.. lets get started!
  6. Some people have very strong views about testing. They just have to have tests no matter what!
  7. No, they really may be intimidating. But, what I want to do here is to NOT try and enforce my opinion, but lay down MY thoughts about testing, what it means to me, how it can help, etc.
  8. I believe in a bit milder approach So, what is test driven development? * Different if you ask different people, can mean a lot of things! - Write tests first … have them fail and then implement features to pass them - Write a lot of tests … ‘test oriented development’ .. this is what I like - Umm people might not always be on-board to this thought
  9. - It is all about testing a small ‘unit’ functionality of code. - In terms of CQ, it can be anything .. ** from testing the ‘activate()’ method of your service .. ** to testing if your servlet responds to a ‘doPost()’ call to .. ** testing if your factory method on a component WORKS - We will be looking at each of these pieces live in action when we get to the ‘looking at the code’ section. ….. QUESTIONS ??
  10. Why is it useful? - Helps to find bugs early. If you have important piece of code and you have tests backing it, over time, its going to be invariably easier to find bugs early during development. - HUGE CODEbase.. new person.. enterprise application codebase. Read tests if you don’t understand the code - And also, if you want to write good tests, you eventually try to make your code sound . Meaning, you use the correct programming patterns. So.. you also get the opportunity to receive kudos! :)
  11. Another one is .. re-factoring. Say eg: YOu have a code which has not been touched for a LONG time. You know.. its like a dark room in your grandma’s house. If you have tests for that implementation, then you are in relatively good shape. Even if I mess things up in my refactoring, you know that that tests can save you. Lastly, a good test is worth a thousand words! This is true .. and you will see it in action soon.
  12. Dan North - Coined the name BDD - Is about Implementing application by describing an application from the perspective of the stakeholders - A new feature requested by the stakeholders is not delivered until it has tests (Code Coverage) - More expressive, readable for humans, than just for computers to execute - Tests whose names are real sentences
  13. Lets take an example of a simple ‘pseudotest’ .. or a ‘usecase’ for a test. We want to assert that a feature in a system works as expected!
  14. If we want to take the TDD or BDD approach * Very natural to read * easy to understand what its doing .. etc. So.. enter Spock framework!
  15. - Enterprise ready testing framework for testing Java and Grooy application - What makes it stand out from the crowd is its highly expressive specification language. - Next generation testing framework! - Spock lets you write specifications that describe expected features (properties, aspects) exhibited by a system of interest. - Why is it awesome? -- Its beautiful.. expressive, based on rspec, junit, etc. -- Easy to learn, powered by Groovy, which is basically java on steroids! -- Several Spock Extensions for like Spring Framework, etc. and it also provides apis to write custom extensions ...QUESTIONS ??
  16. So lets take a simple example of how testing in Spock can look like. Now.. lets take an example of how you can write a simple spock unit test (spec) to test the backend of your component JSP. Every test in Spock is really a ‘feature’, as we saw with regards to BDD, we want to test a feature or a behavior of the system in question.
  17. Mocks - A mock is an object of a certain type but without any behavior. Instead, the expected behavior is specified by the developer writing the specification. setupSpec, cleanupSpec - Runs before 1st feature method, runs after the last feature method ignore - Skipping tests, shared - shared between feature methods / tests …… QUESTIONS??
  18. --- All done using spock.. can be extremely readable and can help understand your system’s usecases better. --- Integration tests for example.. when done in Spock..
  19. It is not just enough to have a lot of tests. I think what will provide real value of the tests, is continuous delivery and integration. So using tools like Jenkins CI, you can basically use these tests as means to catch errors before they go to production, or to user testing.
  20. SUMMARIZING
  21. So answering the question that we asked at the start. The art of programming really lies in being a good programmer that can write code that humans can understand. I believe that having the mindset of writing tests, is going to help you achieve that purpose.
  22. … and that’s it.