Test Driven Development in AEM/CQ5

Preview:

DESCRIPTION

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.

Citation preview

TDD in CQ5/AEMSagar 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

○ Features of Spock Framework

● Much about testing your UI / JS

● Software Consultant II / Tech lead

● WEM Consultant○ Backend development○ 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)

○ Technical meaning○ Design your code around the tests

● Write a lot of tests ○ 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○ 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

//Variablesexpected, v1, v2, ..

//Execute featureactual = System.executeFeature(v1, v2, ..)

//The system gives output as expectedassert actual == expected

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!

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!