SlideShare ist ein Scribd-Unternehmen logo
1 von 74
Downloaden Sie, um offline zu lesen
©ASERT2006-2016
Make your testing Groovy
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
©ASERT2006-2016
Why test with Groovy?
Why test with Groovy?
• Wrong first question!
• … but great second question? 
• Consider first the task at hand and
the organization and people fit!
©ASERT2006-2016
“People Fit” / “Organization Fit”
• People
– 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
©ASERT2006-2016
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
• Disadvantages
– Requires JVM
– Less advantages if your developers using
Python, .Net, PHP
– Maybe your testers already know Ruby
©ASERT2006-2016
Scripting/Dynamic Languages
• Advantages
– 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
©ASERT2006-2016
Test Characteristics…
• Coverage/Traceability
– Requirement coverage/traceability
– Code coverage: line, branch, path, state
– Transactional Tracing
• Purpose
– Unit, Integration, System, Customer
• Manageability
– Removing duplication
– Managing lifecycle: shared setUp/tearDown
(@Before @After)
©ASERT2006-2016
…Test Characteristics
• Handling test data
– 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
©ASERT2006-2016
Key Testing Practices…
• Use testing DSL’s
• Look to move up the testing stack
– 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
©ASERT2006-2016
…Key Testing Practices
• Plug and play testing tools
– Run different drivers with different runners
and different tools
• Complement automated tests with
exploration
• Expand testing scope
– Test environment readiness, test
deployments
©ASERT2006-2016
Groovy and Testing Tool Spectrum*
©ASERT2006-2016
* Tools/libraries/frameworks don't always neatly fall into one category – still useful conceptually
©ASERT2006-2016
What is Groovy?
“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
©ASERT2006-2016
System.out.println("Hello, World!"); // supports Java syntax
println 'Hello, World!' // but can remove some syntax
String name = 'Guillaume' // Explicit typing/awareness
println "$name, I'll get the car." // Gstring (interpolation)
def longer = """${name}, the car
is in the next row.""" // multi-line, implicit type
assert 0.5 == 1/2 // BigDecimal equals()
assert 0.1 + 0.2 == 0.3 // and arithmetic
def printSize(obj) { // implicit/duck typing
print obj?.size() // safe dereferencing
}
def pets = ['ant', 'bee', 'cat'] // literal list syntax
pets.each { pet -> // closure support
assert pet < 'dog' // overloading '<' on String
} // or: for (pet in pets)...
Target audience
• Testing for developers
– Organising tests
– Running tests
– Data generation
– Mocking
– What can be tested
– Code coverage
• Testing beyond developers
– Structuring
– Better reporting
– Data-driven
– Domain specific language (DSL)
– Test coverage
Testing Frameworks
• None
• JUnit 3
• JUnit 4
• JUnit 5
• TestNG
• Spock
Testing Frameworks
• None ???
• JUnit 3
• JUnit 4
• JUnit 5
• TestNG
• Spock
Testing Frameworks
• None ???
– Groovy deems testing so important
that it comes with built-in testing:
– Built-in asserts, mocks
– Built-in JUnit 3 GroovyTestCase and utilities
– Built-in runners for tests
– Bundled JUnit 4
• JUnit 3
• JUnit 4
• JUnit 5
• TestNG
• Spock
Built-in assertions
©ASERT2006-2016
import static Converter.celsius
assert 20 == celsius(68)
assert 35 == celsius(95)
assert -17 == celsius(0).toInteger()
assert 0 == celsius(32)
class Converter {
static celsius (fahrenheit) {
(fahrenheit - 32) * 5 / 9
}
}
Built-in assertions
• But what about errors?
• Groovy’s power Assert mechanism gives
a friendly description of what went wrong
©ASERT2006-2016
Built-in assertions
• But what about errors?
• Groovy’s power Assert mechanism gives
a friendly description of what went wrong
©ASERT2006-2016
GroovyTestCase (extends JUnit 3)
©ASERT2006-2016
import org.junit.Assert
import static Converter.celsius
import static org.junit.Assert.assertEquals
class SimpleGroovyTest extends GroovyTestCase {
void testShouldConvert() {
assert Converter.celsius(68) == 20
assert Converter.celsius(212) == 100, "Should convert boiling"
assertEquals("Should convert freezing", 0.0, celsius(32.0))
assertEquals("Should convert nearly freezing", 0.0, celsius(32.1), 0.1)
}
}
JUnit4
©ASERT2006-2016
import org.junit.Test
import static org.junit.Assert.assertEquals
import static Converter.celsius
class SimpleJUnit4Test {
@Test
void shouldConvert() {
assert celsius(68) == 20
assert celsius(212) == 100, "Should convert boiling"
assertEquals("Should convert freezing", 0.0, celsius(32.0))
assertEquals("Also for nearly freezing", 0.0, celsius(32.1), 0.1)
}
}
JUnit5
©ASERT2006-2016
@Grab('org.junit.platform:junit-platform-runner:1.0.0-M2')
@Grab('org.junit.jupiter:junit-jupiter-engine:5.0.0-M2')
import org.junit.jupiter.api.Test
import org.junit.platform.runner.JUnitPlatform
import org.junit.runner.RunWith
import static Converter.celsius
@RunWith(JUnitPlatform)
class ConverterJUnit5Tests {
@Test
void freezing() {
assert celsius(32) == 0
}
@Test
void boiling() {
assert celsius(212) == 100
}
}
JUnit5
©ASERT2006-2016
@Grab('org.junit.platform:junit-platform-runner:1.0.0-M2')
@Grab('org.junit.jupiter:junit-jupiter-engine:5.0.0-M2')
import org.junit.jupiter.api.Test
import org.junit.platform.runner.JUnitPlatform
import org.junit.runner.RunWith
import static Converter.celsius
@RunWith(JUnitPlatform)
class ConverterJUnit5Tests {
@Test
void freezing() {
assert celsius(32) == 0
}
@Test
void boiling() {
assert celsius(212) == 100
}
}
Spock - BDD style
©ASERT2006-2016
@Grab('org.spockframework:spock-core:1.0-groovy-2.4')
import spock.lang.Specification
class GivenWhenThenSpec extends Specification {
def "test adding a new item to a set"() {
given:
def items = [4, 6, 3, 2] as Set
when:
items << 1
then:
items.size() == 5
}
}
Parameterized
©ASERT2006-2016
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters
import static Converter.celsius
@RunWith(Parameterized)
class DataDrivenJUnitTest {
private c, f, scenario
@Parameters static scenarios() {[
[0, 32, 'Freezing'],
[20, 68, 'Garden party conditions'],
[35, 95, 'Beach conditions'],
[100, 212, 'Boiling']
]*.toArray()}
DataDrivenJUnitTest(c, f, scenario)
this.c = c
this.f = f
this.scenario = scenario
}
@Test void convert() {
def actual = celsius(f)
def msg = "$scenario: ${f}°F should convert into ${c}°C"
assert c == actual, msg
}
}
Spock
©ASERT2006-2016
@Grab('org.spockframework:spock-core:1.0-groovy-2.4')
import spock.lang.*
import static Converter.celsius
class SpockDataDriven extends Specification {
def "test temperature scenarios"() {
expect:
celsius(tempF) == tempC
where:
scenario | tempF || tempC
'Freezing' | 32 || 0
'Garden party conditions' | 68 || 20
'Beach conditions' | 95 || 35
'Boiling' | 212 || 100
}
}
Spock - Celsius
©ASERT2006-2016
@Grab('org.spockframework:spock-core:1.0-groovy-2.4')
import spock.lang.*
import static Converter.celsius
class SpockDataDriven extends Specification {
@Unroll
def "Scenario #scenario: #tempFºF should convert to #tempCºC"() {
expect:
celsius(tempF) == tempC
where:
scenario | tempF || tempC
'Freezing' | 32 || 0
'Garden party conditions' | 68 || 20
'Beach conditions' | 95 || 34
'Boiling' | 212 || 100
}
}
Spock - Celsius
©ASERT2006-2016
@Grab('org.spockframework:spock-core:1.0-groovy-2.4')
import spock.lang.*
import static Converter.celsius
class SpockDataDriven extends Specification {
@Unroll
def "Scenario #scenario: #tempFºF should convert to #tempCºC"() {
expect:
celsius(tempF) == tempC
where:
scenario | tempF || tempC
'Freezing' | 32 || 0
'Garden party conditions' | 68 || 20
'Beach conditions' | 95 || 34
'Boiling' | 212 || 100
}
}
Spock - Mocks
©ASERT2006-2016
@Grab('org.spockframework:spock-core:1.0-groovy-2.4')
import spock.lang.Specification
class SpockMock extends Specification {
def "buy ticket for a movie theater"() {
given:
def purchase = new Purchase("Lord of the Rings", 2)
MovieTheater theater = Mock()
theater.hasSeatsAvailable("Lord of the Rings", 2) >> true
when:
purchase.fill(theater)
then:
purchase.completed
1 * theater.purchaseTicket("Lord of the Rings", 2)
}
}
Spock - Mocks
©ASERT2006-2016
@Grab('org.spockframework:spock-core:1.0-groovy-2.4')
import spock.lang.Specification
class SpockMock extends Specification {
def "buy ticket for a movie theater"() {
given:
def purchase = new Purchase("Lord of the Rings", 2)
MovieTheater theater = Mock()
theater.hasSeatsAvailable("Lord of the Rings", 2) >> true
when:
purchase.fill(theater)
then:
purchase.completed
1 * theater.purchaseTicket("Lord of the Rings", 2)
}
}
Spock - Mocks
©ASERT2006-2016
@Grab('org.spockframework:spock-core:1.0-groovy-2.4')
import spock.lang.Specification
class SpockMockWildcards extends Specification {
def "cannot buy a ticket when the movie is sold out"() {
given:
def purchase = new Purchase("Lord of the rings", 2)
MovieTheater theater = Mock()
when:
theater.hasSeatsAvailable(_, _) >> false
purchase.fill(theater)
then:
!purchase.completed
0 * theater.purchaseTicket(_, _)
}
}
Spock - Mocks
©ASERT2006-2016
@Grab('org.spockframework:spock-core:1.0-groovy-2.4')
import spock.lang.Specification
class SpockMockClosureChecks extends Specification {
def "on couples night tickets are sold in pairs"() {
given:
def purchase = new Purchase("Lord of the Rings", 2)
MovieTheater theater = Mock()
theater.hasSeatsAvailable("Lord of the Rings", 2) >> true
when:
purchase.fill(theater)
then:
1 * theater.purchaseTicket(_, { it % 2 == 0 })
}
}
Assertion frameworks
• None
• JUnit 3 assertions
• Hamcrest
• FEST
• Google truth
assertThat(googleColors).containsNoneOf(PINK, BLACK, WHITE, ORANGE)
assert ![PINK, BLACK, WHITE, ORANGE].any {
color -> color in googleColors }
Property-based testing
• Agile testing game (TDD)
– Minimum test code to steer design of minimal
production code with desired business functionality
but 100% code coverage
– “Grey box” testing
– Rarely used with functional programming
©ASERT2006-2016
Property-based testing
• Agile testing game (TDD)
– Minimum test code to steer design of minimal
production code with desired business functionality
but 100% code coverage
– “Grey box” testing
– Rarely used with functional programming
– Instead validate certain properties
©ASERT2006-2016
Property-based testing
©ASERT2006-2016
@Grab('net.java.quickcheck:quickcheck:0.6')
import static net.java.quickcheck.generator.PrimitiveGenerators.*
import static java.lang.Math.round
import static Converter.celsius
def gen = integers(-40, 240)
def liquidC = 0..100
def liquidF = 32..212
100.times {
int f = gen.next()
int c = round(celsius(f))
assert c <= f
assert c in liquidC == f in liquidF
}
Property-based testing with Spock
©ASERT2006-2016
https://github.com/Bijnagte/spock-genesis
Property-based testing: spock genesis
©ASERT2006-2016
@Grab('com.nagternal:spock-genesis:0.6.0')
@GrabExclude('org.codehaus.groovy:groovy-all')
import spock.genesis.transform.Iterations
import spock.lang.Specification
import static Converter.celsius
import static java.lang.Math.round
import static spock.genesis.Gen.integer
class ConverterSpec extends Specification {
def liquidC = 0..100
def liquidF = 32..212
@Iterations(100)
def "test phase maintained"() {
given:
int tempF = integer(-40..240).iterator().next()
when:
int tempC = round(celsius(tempF))
then:
tempC <= tempF
tempC in liquidC == tempF in liquidF
}
…
Property-based testing: spock genesis
©ASERT2006-2016
@Grab('com.nagternal:spock-genesis:0.6.0')
@GrabExclude('org.codehaus.groovy:groovy-all')
import spock.genesis.transform.Iterations
import spock.lang.Specification
import static Converter.celsius
import static java.lang.Math.round
import static spock.genesis.Gen.integer
class ConverterSpec extends Specification {
def liquidC = 0..100
def liquidF = 32..212
@Iterations(100)
def "test phase maintained"() {
given:
int tempF = integer(-40..240).iterator().next()
when:
int tempC = round(celsius(tempF))
then:
tempC <= tempF
tempC in liquidC == tempF in liquidF
}
…
…
@Iterations(100)
def "test order maintained"() {
given:
int tempF1 = integer(-273..999).iterator().next()
int tempF2 = integer(-273..999).iterator().next()
when:
int tempC1 = round(celsius(tempF1))
int tempC2 = round(celsius(tempF2))
then:
(tempF1 <=> tempF2) == (tempC1 <=> tempC2)
}
}
Case Study
Case Study
Case Study
Case Study
Case Study
Case Study
Case Study
Case Study
Case Study
Case Study
Case Study
Case Study
Case Study
All Combinations
All Combinations Case Study
All Pairs
All Pairs Case Study
GPars
• Library classes and DSL allowing
you to handle tasks concurrently:
– Data Parallelism map, filter, reduce functionality
in parallel with parallel array support
– Asynchronous functions extend the Java
executor services to enable multi-threaded
closure processing
– Dataflow Concurrency supports natural
shared-memory concurrency model, using
single-assignment variables
– Actors provide Erlang/Scala-like actors
including "remote" actors on other machines
– Safe Agents provide a non-blocking mt-safe
reference to mutable state; like "agents" in Clojure
8
Case Study with GPars
Constraint/Logic Programming
• Description
– Style of programming where relations between
variables are stated in the form of constraints
– First made popular by logic programming languages
such as Prolog but the style is now also used outside
logic programming specific languages
– Constraints differ from the common primitives of
other programming languages in that they do not
specify one or more steps to execute but rather the
properties of a solution to be found
– Popular libraries used with Groovy supporting
constraint programming include Gecode/J, Choco
and tuProlog
– We'll look at Choco as an example
Case Study with Constraint Programming
• You have been asked to set up some test
cases representing the Simpsons’ weekly
blogging habits
• After some careful study you observe the
following strange behavior
– They never blog on the same day
– Marge blogs only on a Saturday or Sunday
– Maggie blogs only on a Tuesday or Thursday
– Lisa blogs only on a Monday, Wednesday or Friday
– Bart blogs only on the day after Lisa
– Homer only blogs if noone else blogged the previous
day and doesn't allow anyone to blog the next day
Case Study with Constraint Programming
Case Study with Constraint Programming
Case Study with Constraint Programming
ModelJUnit
ModelJUnit
ModelJUnit
Case Study with ModelJUnit
Case Study with ModelJUnit
Case Study with ModelJUnit
Case Study with ModelJUnit
Case Study with ModelJUnit
Testing DSLs
• Low-level DSL
• Higher-level DSL
post blog from Bart with title "Bart rulz!" and category School and content "Cowabunga Dude!"
More Information: Groovy in Action

Weitere ähnliche Inhalte

Ähnlich wie Make Your Testing Groovy

Make Testing Groovy
Make Testing GroovyMake Testing Groovy
Make Testing GroovyPaul King
 
Continuous Load Testing with CloudTest and Jenkins
Continuous Load Testing with CloudTest and JenkinsContinuous Load Testing with CloudTest and Jenkins
Continuous Load Testing with CloudTest and JenkinsSOASTA
 
Continuous Load Testing with CloudTest and Jenkins
Continuous Load Testing with CloudTest and JenkinsContinuous Load Testing with CloudTest and Jenkins
Continuous Load Testing with CloudTest and JenkinsSOASTA
 
New types of tests for Java projects
New types of tests for Java projectsNew types of tests for Java projects
New types of tests for Java projectsVincent Massol
 
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)Christian Catalan
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testabilitydrewz lin
 
Comparing Functionalities of PVS-Studio and CppCat Static Code Analyzers
Comparing Functionalities of PVS-Studio and CppCat Static Code AnalyzersComparing Functionalities of PVS-Studio and CppCat Static Code Analyzers
Comparing Functionalities of PVS-Studio and CppCat Static Code AnalyzersAndrey Karpov
 
Fostering Long-Term Test Automation Success
Fostering Long-Term Test Automation SuccessFostering Long-Term Test Automation Success
Fostering Long-Term Test Automation SuccessJosiah Renaudin
 
AQAvit: Vitality through Testing
AQAvit: Vitality through TestingAQAvit: Vitality through Testing
AQAvit: Vitality through TestingShelley Lambert
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Yves Hoppe
 
Jonathon Wright - Intelligent Performance Cognitive Learning (AIOps)
Jonathon Wright - Intelligent Performance Cognitive Learning (AIOps)Jonathon Wright - Intelligent Performance Cognitive Learning (AIOps)
Jonathon Wright - Intelligent Performance Cognitive Learning (AIOps)Neotys_Partner
 
A CI/CD Pipeline to Deploy and Maintain OpenStack - cfgmgmtcamp2015
A CI/CD Pipeline to Deploy and Maintain OpenStack - cfgmgmtcamp2015A CI/CD Pipeline to Deploy and Maintain OpenStack - cfgmgmtcamp2015
A CI/CD Pipeline to Deploy and Maintain OpenStack - cfgmgmtcamp2015Simon McCartney
 
Kirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for AutomatizationKirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for AutomatizationSergey Arkhipov
 
Code Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application MigrationsCode Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application MigrationsDana Luther
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Paul King
 
Agile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source FrameworksAgile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source FrameworksViraf Karai
 
Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!Craig Smith
 
Java SE SQE IEC Ops Review Fy09 April 09
Java SE SQE IEC Ops Review Fy09 April 09Java SE SQE IEC Ops Review Fy09 April 09
Java SE SQE IEC Ops Review Fy09 April 09rabic
 

Ähnlich wie Make Your Testing Groovy (20)

Make Testing Groovy
Make Testing GroovyMake Testing Groovy
Make Testing Groovy
 
Advanced Java Testing
Advanced Java TestingAdvanced Java Testing
Advanced Java Testing
 
Continuous Load Testing with CloudTest and Jenkins
Continuous Load Testing with CloudTest and JenkinsContinuous Load Testing with CloudTest and Jenkins
Continuous Load Testing with CloudTest and Jenkins
 
Continuous Load Testing with CloudTest and Jenkins
Continuous Load Testing with CloudTest and JenkinsContinuous Load Testing with CloudTest and Jenkins
Continuous Load Testing with CloudTest and Jenkins
 
New types of tests for Java projects
New types of tests for Java projectsNew types of tests for Java projects
New types of tests for Java projects
 
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability
 
Comparing Functionalities of PVS-Studio and CppCat Static Code Analyzers
Comparing Functionalities of PVS-Studio and CppCat Static Code AnalyzersComparing Functionalities of PVS-Studio and CppCat Static Code Analyzers
Comparing Functionalities of PVS-Studio and CppCat Static Code Analyzers
 
Fostering Long-Term Test Automation Success
Fostering Long-Term Test Automation SuccessFostering Long-Term Test Automation Success
Fostering Long-Term Test Automation Success
 
AQAvit: Vitality through Testing
AQAvit: Vitality through TestingAQAvit: Vitality through Testing
AQAvit: Vitality through Testing
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016
 
Jonathon Wright - Intelligent Performance Cognitive Learning (AIOps)
Jonathon Wright - Intelligent Performance Cognitive Learning (AIOps)Jonathon Wright - Intelligent Performance Cognitive Learning (AIOps)
Jonathon Wright - Intelligent Performance Cognitive Learning (AIOps)
 
A CI/CD Pipeline to Deploy and Maintain OpenStack - cfgmgmtcamp2015
A CI/CD Pipeline to Deploy and Maintain OpenStack - cfgmgmtcamp2015A CI/CD Pipeline to Deploy and Maintain OpenStack - cfgmgmtcamp2015
A CI/CD Pipeline to Deploy and Maintain OpenStack - cfgmgmtcamp2015
 
Kirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for AutomatizationKirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for Automatization
 
Code Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application MigrationsCode Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application Migrations
 
Unit testing js
Unit testing jsUnit testing js
Unit testing js
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
 
Agile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source FrameworksAgile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source Frameworks
 
Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!
 
Java SE SQE IEC Ops Review Fy09 April 09
Java SE SQE IEC Ops Review Fy09 April 09Java SE SQE IEC Ops Review Fy09 April 09
Java SE SQE IEC Ops Review Fy09 April 09
 

Mehr von Paul King

awesome groovy
awesome groovyawesome groovy
awesome groovyPaul King
 
groovy databases
groovy databasesgroovy databases
groovy databasesPaul King
 
groovy transforms
groovy transformsgroovy transforms
groovy transformsPaul King
 
concurrency gpars
concurrency gparsconcurrency gpars
concurrency gparsPaul King
 
tictactoe groovy
tictactoe groovytictactoe groovy
tictactoe groovyPaul King
 
groovy rules
groovy rulesgroovy rules
groovy rulesPaul King
 
functional groovy
functional groovyfunctional groovy
functional groovyPaul King
 
Agile Testing Practices
Agile Testing PracticesAgile Testing Practices
Agile Testing PracticesPaul King
 
groovy DSLs from beginner to expert
groovy DSLs from beginner to expertgroovy DSLs from beginner to expert
groovy DSLs from beginner to expertPaul King
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GParsPaul King
 
groovy and concurrency
groovy and concurrencygroovy and concurrency
groovy and concurrencyPaul King
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy PluginsPaul King
 
Dynamic Language Practices
Dynamic Language PracticesDynamic Language Practices
Dynamic Language PracticesPaul King
 
Make Your Builds More Groovy
Make Your Builds More GroovyMake Your Builds More Groovy
Make Your Builds More GroovyPaul King
 
Groovy Power Features
Groovy Power FeaturesGroovy Power Features
Groovy Power FeaturesPaul King
 
Craig Smith & Paul King Agile Tool Hacking Taking Your Agile Development ...
Craig Smith & Paul King   Agile Tool Hacking   Taking Your Agile Development ...Craig Smith & Paul King   Agile Tool Hacking   Taking Your Agile Development ...
Craig Smith & Paul King Agile Tool Hacking Taking Your Agile Development ...Paul King
 
Groovy Tutorial
Groovy TutorialGroovy Tutorial
Groovy TutorialPaul King
 
XML and Web Services with Groovy
XML and Web Services with GroovyXML and Web Services with Groovy
XML and Web Services with GroovyPaul King
 

Mehr von Paul King (19)

awesome groovy
awesome groovyawesome groovy
awesome groovy
 
groovy databases
groovy databasesgroovy databases
groovy databases
 
groovy transforms
groovy transformsgroovy transforms
groovy transforms
 
concurrency gpars
concurrency gparsconcurrency gpars
concurrency gpars
 
tictactoe groovy
tictactoe groovytictactoe groovy
tictactoe groovy
 
groovy rules
groovy rulesgroovy rules
groovy rules
 
functional groovy
functional groovyfunctional groovy
functional groovy
 
Agile Testing Practices
Agile Testing PracticesAgile Testing Practices
Agile Testing Practices
 
groovy DSLs from beginner to expert
groovy DSLs from beginner to expertgroovy DSLs from beginner to expert
groovy DSLs from beginner to expert
 
concurrency with GPars
concurrency with GParsconcurrency with GPars
concurrency with GPars
 
groovy and concurrency
groovy and concurrencygroovy and concurrency
groovy and concurrency
 
GroovyDSLs
GroovyDSLsGroovyDSLs
GroovyDSLs
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
Dynamic Language Practices
Dynamic Language PracticesDynamic Language Practices
Dynamic Language Practices
 
Make Your Builds More Groovy
Make Your Builds More GroovyMake Your Builds More Groovy
Make Your Builds More Groovy
 
Groovy Power Features
Groovy Power FeaturesGroovy Power Features
Groovy Power Features
 
Craig Smith & Paul King Agile Tool Hacking Taking Your Agile Development ...
Craig Smith & Paul King   Agile Tool Hacking   Taking Your Agile Development ...Craig Smith & Paul King   Agile Tool Hacking   Taking Your Agile Development ...
Craig Smith & Paul King Agile Tool Hacking Taking Your Agile Development ...
 
Groovy Tutorial
Groovy TutorialGroovy Tutorial
Groovy Tutorial
 
XML and Web Services with Groovy
XML and Web Services with GroovyXML and Web Services with Groovy
XML and Web Services with Groovy
 

Kürzlich hochgeladen

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 

Make Your Testing Groovy

  • 1. ©ASERT2006-2016 Make your testing Groovy 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
  • 3. Why test with Groovy? • Wrong first question! • … but great second question?  • Consider first the task at hand and the organization and people fit! ©ASERT2006-2016
  • 4. “People Fit” / “Organization Fit” • People – 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 ©ASERT2006-2016
  • 5. 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 • Disadvantages – Requires JVM – Less advantages if your developers using Python, .Net, PHP – Maybe your testers already know Ruby ©ASERT2006-2016
  • 6. Scripting/Dynamic Languages • Advantages – 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 ©ASERT2006-2016
  • 7. Test Characteristics… • Coverage/Traceability – Requirement coverage/traceability – Code coverage: line, branch, path, state – Transactional Tracing • Purpose – Unit, Integration, System, Customer • Manageability – Removing duplication – Managing lifecycle: shared setUp/tearDown (@Before @After) ©ASERT2006-2016
  • 8. …Test Characteristics • Handling test data – 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 ©ASERT2006-2016
  • 9. Key Testing Practices… • Use testing DSL’s • Look to move up the testing stack – 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 ©ASERT2006-2016
  • 10. …Key Testing Practices • Plug and play testing tools – Run different drivers with different runners and different tools • Complement automated tests with exploration • Expand testing scope – Test environment readiness, test deployments ©ASERT2006-2016
  • 11. Groovy and Testing Tool Spectrum* ©ASERT2006-2016 * Tools/libraries/frameworks don't always neatly fall into one category – still useful conceptually
  • 12. ©ASERT2006-2016 What is Groovy? “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
  • 13. Groovy starter ©ASERT2006-2016 System.out.println("Hello, World!"); // supports Java syntax println 'Hello, World!' // but can remove some syntax String name = 'Guillaume' // Explicit typing/awareness println "$name, I'll get the car." // Gstring (interpolation) def longer = """${name}, the car is in the next row.""" // multi-line, implicit type assert 0.5 == 1/2 // BigDecimal equals() assert 0.1 + 0.2 == 0.3 // and arithmetic def printSize(obj) { // implicit/duck typing print obj?.size() // safe dereferencing } def pets = ['ant', 'bee', 'cat'] // literal list syntax pets.each { pet -> // closure support assert pet < 'dog' // overloading '<' on String } // or: for (pet in pets)...
  • 14. Target audience • Testing for developers – Organising tests – Running tests – Data generation – Mocking – What can be tested – Code coverage • Testing beyond developers – Structuring – Better reporting – Data-driven – Domain specific language (DSL) – Test coverage
  • 15. Testing Frameworks • None • JUnit 3 • JUnit 4 • JUnit 5 • TestNG • Spock
  • 16. Testing Frameworks • None ??? • JUnit 3 • JUnit 4 • JUnit 5 • TestNG • Spock
  • 17. Testing Frameworks • None ??? – Groovy deems testing so important that it comes with built-in testing: – Built-in asserts, mocks – Built-in JUnit 3 GroovyTestCase and utilities – Built-in runners for tests – Bundled JUnit 4 • JUnit 3 • JUnit 4 • JUnit 5 • TestNG • Spock
  • 18. Built-in assertions ©ASERT2006-2016 import static Converter.celsius assert 20 == celsius(68) assert 35 == celsius(95) assert -17 == celsius(0).toInteger() assert 0 == celsius(32) class Converter { static celsius (fahrenheit) { (fahrenheit - 32) * 5 / 9 } }
  • 19. Built-in assertions • But what about errors? • Groovy’s power Assert mechanism gives a friendly description of what went wrong ©ASERT2006-2016
  • 20. Built-in assertions • But what about errors? • Groovy’s power Assert mechanism gives a friendly description of what went wrong ©ASERT2006-2016
  • 21. GroovyTestCase (extends JUnit 3) ©ASERT2006-2016 import org.junit.Assert import static Converter.celsius import static org.junit.Assert.assertEquals class SimpleGroovyTest extends GroovyTestCase { void testShouldConvert() { assert Converter.celsius(68) == 20 assert Converter.celsius(212) == 100, "Should convert boiling" assertEquals("Should convert freezing", 0.0, celsius(32.0)) assertEquals("Should convert nearly freezing", 0.0, celsius(32.1), 0.1) } }
  • 22. JUnit4 ©ASERT2006-2016 import org.junit.Test import static org.junit.Assert.assertEquals import static Converter.celsius class SimpleJUnit4Test { @Test void shouldConvert() { assert celsius(68) == 20 assert celsius(212) == 100, "Should convert boiling" assertEquals("Should convert freezing", 0.0, celsius(32.0)) assertEquals("Also for nearly freezing", 0.0, celsius(32.1), 0.1) } }
  • 23. JUnit5 ©ASERT2006-2016 @Grab('org.junit.platform:junit-platform-runner:1.0.0-M2') @Grab('org.junit.jupiter:junit-jupiter-engine:5.0.0-M2') import org.junit.jupiter.api.Test import org.junit.platform.runner.JUnitPlatform import org.junit.runner.RunWith import static Converter.celsius @RunWith(JUnitPlatform) class ConverterJUnit5Tests { @Test void freezing() { assert celsius(32) == 0 } @Test void boiling() { assert celsius(212) == 100 } }
  • 24. JUnit5 ©ASERT2006-2016 @Grab('org.junit.platform:junit-platform-runner:1.0.0-M2') @Grab('org.junit.jupiter:junit-jupiter-engine:5.0.0-M2') import org.junit.jupiter.api.Test import org.junit.platform.runner.JUnitPlatform import org.junit.runner.RunWith import static Converter.celsius @RunWith(JUnitPlatform) class ConverterJUnit5Tests { @Test void freezing() { assert celsius(32) == 0 } @Test void boiling() { assert celsius(212) == 100 } }
  • 25. Spock - BDD style ©ASERT2006-2016 @Grab('org.spockframework:spock-core:1.0-groovy-2.4') import spock.lang.Specification class GivenWhenThenSpec extends Specification { def "test adding a new item to a set"() { given: def items = [4, 6, 3, 2] as Set when: items << 1 then: items.size() == 5 } }
  • 26. Parameterized ©ASERT2006-2016 import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized import org.junit.runners.Parameterized.Parameters import static Converter.celsius @RunWith(Parameterized) class DataDrivenJUnitTest { private c, f, scenario @Parameters static scenarios() {[ [0, 32, 'Freezing'], [20, 68, 'Garden party conditions'], [35, 95, 'Beach conditions'], [100, 212, 'Boiling'] ]*.toArray()} DataDrivenJUnitTest(c, f, scenario) this.c = c this.f = f this.scenario = scenario } @Test void convert() { def actual = celsius(f) def msg = "$scenario: ${f}°F should convert into ${c}°C" assert c == actual, msg } }
  • 27. Spock ©ASERT2006-2016 @Grab('org.spockframework:spock-core:1.0-groovy-2.4') import spock.lang.* import static Converter.celsius class SpockDataDriven extends Specification { def "test temperature scenarios"() { expect: celsius(tempF) == tempC where: scenario | tempF || tempC 'Freezing' | 32 || 0 'Garden party conditions' | 68 || 20 'Beach conditions' | 95 || 35 'Boiling' | 212 || 100 } }
  • 28. Spock - Celsius ©ASERT2006-2016 @Grab('org.spockframework:spock-core:1.0-groovy-2.4') import spock.lang.* import static Converter.celsius class SpockDataDriven extends Specification { @Unroll def "Scenario #scenario: #tempFºF should convert to #tempCºC"() { expect: celsius(tempF) == tempC where: scenario | tempF || tempC 'Freezing' | 32 || 0 'Garden party conditions' | 68 || 20 'Beach conditions' | 95 || 34 'Boiling' | 212 || 100 } }
  • 29. Spock - Celsius ©ASERT2006-2016 @Grab('org.spockframework:spock-core:1.0-groovy-2.4') import spock.lang.* import static Converter.celsius class SpockDataDriven extends Specification { @Unroll def "Scenario #scenario: #tempFºF should convert to #tempCºC"() { expect: celsius(tempF) == tempC where: scenario | tempF || tempC 'Freezing' | 32 || 0 'Garden party conditions' | 68 || 20 'Beach conditions' | 95 || 34 'Boiling' | 212 || 100 } }
  • 30. Spock - Mocks ©ASERT2006-2016 @Grab('org.spockframework:spock-core:1.0-groovy-2.4') import spock.lang.Specification class SpockMock extends Specification { def "buy ticket for a movie theater"() { given: def purchase = new Purchase("Lord of the Rings", 2) MovieTheater theater = Mock() theater.hasSeatsAvailable("Lord of the Rings", 2) >> true when: purchase.fill(theater) then: purchase.completed 1 * theater.purchaseTicket("Lord of the Rings", 2) } }
  • 31. Spock - Mocks ©ASERT2006-2016 @Grab('org.spockframework:spock-core:1.0-groovy-2.4') import spock.lang.Specification class SpockMock extends Specification { def "buy ticket for a movie theater"() { given: def purchase = new Purchase("Lord of the Rings", 2) MovieTheater theater = Mock() theater.hasSeatsAvailable("Lord of the Rings", 2) >> true when: purchase.fill(theater) then: purchase.completed 1 * theater.purchaseTicket("Lord of the Rings", 2) } }
  • 32. Spock - Mocks ©ASERT2006-2016 @Grab('org.spockframework:spock-core:1.0-groovy-2.4') import spock.lang.Specification class SpockMockWildcards extends Specification { def "cannot buy a ticket when the movie is sold out"() { given: def purchase = new Purchase("Lord of the rings", 2) MovieTheater theater = Mock() when: theater.hasSeatsAvailable(_, _) >> false purchase.fill(theater) then: !purchase.completed 0 * theater.purchaseTicket(_, _) } }
  • 33. Spock - Mocks ©ASERT2006-2016 @Grab('org.spockframework:spock-core:1.0-groovy-2.4') import spock.lang.Specification class SpockMockClosureChecks extends Specification { def "on couples night tickets are sold in pairs"() { given: def purchase = new Purchase("Lord of the Rings", 2) MovieTheater theater = Mock() theater.hasSeatsAvailable("Lord of the Rings", 2) >> true when: purchase.fill(theater) then: 1 * theater.purchaseTicket(_, { it % 2 == 0 }) } }
  • 34. Assertion frameworks • None • JUnit 3 assertions • Hamcrest • FEST • Google truth assertThat(googleColors).containsNoneOf(PINK, BLACK, WHITE, ORANGE) assert ![PINK, BLACK, WHITE, ORANGE].any { color -> color in googleColors }
  • 35. Property-based testing • Agile testing game (TDD) – Minimum test code to steer design of minimal production code with desired business functionality but 100% code coverage – “Grey box” testing – Rarely used with functional programming ©ASERT2006-2016
  • 36. Property-based testing • Agile testing game (TDD) – Minimum test code to steer design of minimal production code with desired business functionality but 100% code coverage – “Grey box” testing – Rarely used with functional programming – Instead validate certain properties ©ASERT2006-2016
  • 37. Property-based testing ©ASERT2006-2016 @Grab('net.java.quickcheck:quickcheck:0.6') import static net.java.quickcheck.generator.PrimitiveGenerators.* import static java.lang.Math.round import static Converter.celsius def gen = integers(-40, 240) def liquidC = 0..100 def liquidF = 32..212 100.times { int f = gen.next() int c = round(celsius(f)) assert c <= f assert c in liquidC == f in liquidF }
  • 38. Property-based testing with Spock ©ASERT2006-2016 https://github.com/Bijnagte/spock-genesis
  • 39. Property-based testing: spock genesis ©ASERT2006-2016 @Grab('com.nagternal:spock-genesis:0.6.0') @GrabExclude('org.codehaus.groovy:groovy-all') import spock.genesis.transform.Iterations import spock.lang.Specification import static Converter.celsius import static java.lang.Math.round import static spock.genesis.Gen.integer class ConverterSpec extends Specification { def liquidC = 0..100 def liquidF = 32..212 @Iterations(100) def "test phase maintained"() { given: int tempF = integer(-40..240).iterator().next() when: int tempC = round(celsius(tempF)) then: tempC <= tempF tempC in liquidC == tempF in liquidF } …
  • 40. Property-based testing: spock genesis ©ASERT2006-2016 @Grab('com.nagternal:spock-genesis:0.6.0') @GrabExclude('org.codehaus.groovy:groovy-all') import spock.genesis.transform.Iterations import spock.lang.Specification import static Converter.celsius import static java.lang.Math.round import static spock.genesis.Gen.integer class ConverterSpec extends Specification { def liquidC = 0..100 def liquidF = 32..212 @Iterations(100) def "test phase maintained"() { given: int tempF = integer(-40..240).iterator().next() when: int tempC = round(celsius(tempF)) then: tempC <= tempF tempC in liquidC == tempF in liquidF } … … @Iterations(100) def "test order maintained"() { given: int tempF1 = integer(-273..999).iterator().next() int tempF2 = integer(-273..999).iterator().next() when: int tempC1 = round(celsius(tempF1)) int tempC2 = round(celsius(tempF2)) then: (tempF1 <=> tempF2) == (tempC1 <=> tempC2) } }
  • 57. All Pairs Case Study
  • 58. GPars • Library classes and DSL allowing you to handle tasks concurrently: – Data Parallelism map, filter, reduce functionality in parallel with parallel array support – Asynchronous functions extend the Java executor services to enable multi-threaded closure processing – Dataflow Concurrency supports natural shared-memory concurrency model, using single-assignment variables – Actors provide Erlang/Scala-like actors including "remote" actors on other machines – Safe Agents provide a non-blocking mt-safe reference to mutable state; like "agents" in Clojure 8
  • 60. Constraint/Logic Programming • Description – Style of programming where relations between variables are stated in the form of constraints – First made popular by logic programming languages such as Prolog but the style is now also used outside logic programming specific languages – Constraints differ from the common primitives of other programming languages in that they do not specify one or more steps to execute but rather the properties of a solution to be found – Popular libraries used with Groovy supporting constraint programming include Gecode/J, Choco and tuProlog – We'll look at Choco as an example
  • 61. Case Study with Constraint Programming • You have been asked to set up some test cases representing the Simpsons’ weekly blogging habits • After some careful study you observe the following strange behavior – They never blog on the same day – Marge blogs only on a Saturday or Sunday – Maggie blogs only on a Tuesday or Thursday – Lisa blogs only on a Monday, Wednesday or Friday – Bart blogs only on the day after Lisa – Homer only blogs if noone else blogged the previous day and doesn't allow anyone to blog the next day
  • 62. Case Study with Constraint Programming
  • 63. Case Study with Constraint Programming
  • 64. Case Study with Constraint Programming
  • 68. Case Study with ModelJUnit
  • 69. Case Study with ModelJUnit
  • 70. Case Study with ModelJUnit
  • 71. Case Study with ModelJUnit
  • 72. Case Study with ModelJUnit
  • 73. Testing DSLs • Low-level DSL • Higher-level DSL post blog from Bart with title "Bart rulz!" and category School and content "Cowabunga Dude!"