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
Test Driven Development in CQ5/AEM
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

PDF
Test Driven Development in AEM/CQ5
PDF
Using The Page Object Pattern
PPTX
Introduction to Bdd and cucumber
PDF
Cucumber ppt
PPT
Intro to Service Worker API and its use cases
PDF
Perils of Page-Object Pattern
PDF
BDD in PHP - Behat
PPTX
Test Automation Framework with BDD and Cucumber
Test Driven Development in AEM/CQ5
Using The Page Object Pattern
Introduction to Bdd and cucumber
Cucumber ppt
Intro to Service Worker API and its use cases
Perils of Page-Object Pattern
BDD in PHP - Behat
Test Automation Framework with BDD and Cucumber

What's hot (20)

PDF
Yet Another Continuous Integration Story
PPTX
BDD with SpecFlow and Selenium
ODP
Test Automation Framework using Cucumber BDD overview (part 1)
PPTX
Cucumber BDD
PPTX
PPTX
Behat - human-readable automated testing
ODP
BDD with Behat
PDF
DDD with Behat
PPTX
BDD and Behave
PPTX
HotelQuickly Product & Engineering
PDF
Contributing to open source
PDF
Making cross browser tests beautiful
PPTX
Selenium + Specflow
PPTX
Bdd – with cucumber and gherkin
PPTX
Automation test framework with cucumber – BDD
PDF
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
PPTX
BDD testing with cucumber
PPTX
What Is Cucumber?
ODP
Behavior Driven GUI Testing
PDF
iOS development best practices
Yet Another Continuous Integration Story
BDD with SpecFlow and Selenium
Test Automation Framework using Cucumber BDD overview (part 1)
Cucumber BDD
Behat - human-readable automated testing
BDD with Behat
DDD with Behat
BDD and Behave
HotelQuickly Product & Engineering
Contributing to open source
Making cross browser tests beautiful
Selenium + Specflow
Bdd – with cucumber and gherkin
Automation test framework with cucumber – BDD
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
BDD testing with cucumber
What Is Cucumber?
Behavior Driven GUI Testing
iOS development best practices
Ad

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

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

Recently uploaded (20)

PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
ai tools demonstartion for schools and inter college
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
AI in Product Development-omnex systems
PDF
System and Network Administraation Chapter 3
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
System and Network Administration Chapter 2
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Digital Strategies for Manufacturing Companies
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Nekopoi APK 2025 free lastest update
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
ai tools demonstartion for schools and inter college
CHAPTER 2 - PM Management and IT Context
How Creative Agencies Leverage Project Management Software.pdf
Understanding Forklifts - TECH EHS Solution
AI in Product Development-omnex systems
System and Network Administraation Chapter 3
L1 - Introduction to python Backend.pptx
Online Work Permit System for Fast Permit Processing
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Design an Analysis of Algorithms II-SECS-1021-03
Design an Analysis of Algorithms I-SECS-1021-03
Adobe Illustrator 28.6 Crack My Vision of Vector Design
System and Network Administration Chapter 2
ISO 45001 Occupational Health and Safety Management System
Digital Strategies for Manufacturing Companies
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
ManageIQ - Sprint 268 Review - Slide Deck
Nekopoi APK 2025 free lastest update
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...

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
  • 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

  • #2: Hello everyone… Thanks for joining, today we will be talking about Test Driven Development. - Testing during development.
  • #3: 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!
  • #4: .. 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
  • #5: I am this.. that.. PAUSE...
  • #6: 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!
  • #7: Some people have very strong views about testing. They just have to have tests no matter what!
  • #8: 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.
  • #9: 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
  • #10: - 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 ??
  • #11: 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! :)
  • #12: 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.
  • #13: 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
  • #14: 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!
  • #15: 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!
  • #16: - 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 ??
  • #17: 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.
  • #18: 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??
  • #19: --- 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..
  • #20: 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.
  • #21: SUMMARIZING
  • #22: 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.
  • #23: … and that’s it.