Presentation from RTP AEM / CQ5 Meetup by Sagar Sane. This presentation provides some of the challenges and benefits of applying Test Driven Development principles to Adobe Experience Manager (AEM)/CQ5 based projects and overview of some of the tools and technologies, including Spock & Geb, which can be used for automating test cases & execution.
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
○ Features of Spock Framework
● Much about testing your UI / JS
4. ● Software Consultant II / Tech lead
● WEM Consultant
○ Backend development
○ 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..
8. Test Driven Development
● Write Test First (extreme programming)
○ Technical meaning
○ Design your code around the tests
● Write a lot of tests
○ Milder approach
10. Benefits of Testing
● Find bugs early
● Make it easy for a new person on your
project
○ 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 ]
○ 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)