Make your testing Groovy © ASERT 2006-2016

Dr Paul King Groovy Lead for Object Computing Inc. @paulk_asert http:/slideshare.net/paulk_asert/make-tests-groovy https://github.com/paulk-asert/MakeTestingGroovy

Why test with Groovy?

© ASERT 2006-2016

Why test with Groovy?

• Wrong first question! • … but great second question? 

© ASERT 2006-2016

• Consider first the task at hand and the organization and people fit!

“People Fit” / “Organization Fit”

• People

© ASERT 2006-2016

– – – – – –

Developers (familiarity with languages) Testers (tools language familiarity) Responsibility to create/run/maintain BAs/SMEs (ability to read technical tests) Consider both development and maintenance Expected feedback from tests (JUnit/Reports)

• Organization – – – –

Maturity level Degree of automation Tools in use Need for adaptability

Why Test With Groovy?

• Advantages – – – –

Easy to learn Particularly good for Java shops Easy to plug and play different testing tools Good community & tools for professional agile

© ASERT 2006-2016

• Disadvantages – Requires JVM – Less advantages if your developers using Python, .Net, PHP – Maybe your testers already know Ruby

Scripting/Dynamic Languages

• Advantages

© ASERT 2006-2016

– – – – – – –

Lend themselves to succinct code/DSLs Powerful Increased Refactoring Increased Reuse Less prone to Brittleness Flexibility for tool integration Open APIs provide extensibility

• Disadvantages – Can be too low level – Sometimes less tool support

Test Characteristics…

• Coverage/Traceability – Requirement coverage/traceability – Code coverage: line, branch, path, state – Transactional Tracing © ASERT 2006-2016

• Purpose – Unit, Integration, System, Customer

• Manageability – Removing duplication – Managing lifecycle: shared setUp/tearDown (@Before @After)

…Test Characteristics

• Handling test data

© ASERT 2006-2016

– Data-driven, databases, Spreadsheets, tables, keywords, random, model-driven – Large Test Volumes – Speed of feedback, performance testing

• Tool evolution, longevity, cost, support, documentation – Open Source/Commercial, Critical mass/popularity

• Combinability

Key Testing Practices…

• Use testing DSL’s • Look to move up the testing stack

© ASERT 2006-2016

– It used to be all about the driver – Now the driver is hidden in the framework or tool stack

• Apply good testing practices – Pareto analysis, bug clusters, mutation testing, test early, all pairs/equivalence partitions/orthogonal array testing, risk-based test selection, coding for testability, use CI, boundary value analysis, defensive programming

…Key Testing Practices

• Plug and play testing tools – Run different drivers with different runners and different tools

© ASERT 2006-2016

• Complement automated tests with exploration • Expand testing scope – Test environment readiness, test deployments

Groovy and Testing Tool Spectrum*

© ASERT 2006-2016

* Tools/libraries/frameworks don't always neatly fall into one category – still useful conceptually

What is Groovy?

© ASERT 2006-2016

“Groovy is like a super version of Java. It leverages Java features but adds productivity features and provides great flexibility and extensibility.” Groovy = Java – + + +

boiler plate code closures (1st class FP) extensible type system runtime & compile-time metaprogramming + flexible grammar (DSLs) + scripting & GDK library

Groovy starter

© ASERT 2006-2016

System.out.println("Hello, World!"); println 'Hello, World!'

// supports Java syntax // but can remove some syntax

String name = 'Guillaume' println "$name, I'll get the car."

// Explicit typing/awareness // Gstring (interpolation)

def longer = """${name}, the car is in the next row."""

// multi-line, implicit type

assert 0.5 == 1/2 assert 0.1 + 0.2 == 0.3

// BigDecimal equals() // and arithmetic

def printSize(obj) { print obj?.size() }

// implicit/duck typing // safe dereferencing

def pets = ['ant', 'bee', 'cat'] pets.each { pet -> assert pet < 'dog' }

// // // //

literal list syntax closure support overloading '