SlideShare a Scribd company logo
Applause
www.applause.com
❏ Crowd Testing
❏ Beta Distributions
❏ Crash Reports
❏ Application Analytics
❏ We’re hiring!
Przemek Jakubczyk
Senior Android Developer
Applause Inc
pjakubczyk@gmail.com
GH: pjakubczyk
Robospock
def "should change label on button click"(){
given:
def button = new Button()
when:
button.click()
then:
button.getLabel() == "The new label"
}
def "should change label on button click"(){
given:
def button = new Button()
when:
button.click()
then:
button.getLabel() == "The new label"
}
@Test
public void shouldChangeLabelOnButtonClick(){
//given
Button button = new Button();
// when
button.click();
// then
Assert.assertEquals("The new label",
button.getLabel());
}
def "should throw RuntimeException on button click"(){
given:
def button = new Button()
when:
button.click()
then:
thrown(RuntimeException)
}
def "should throw RuntimeException on button click"(){
given:
def button = new Button()
when:
button.click()
then:
thrown(RuntimeException)
}
@Test(expected = RuntimeException.class)
public void
shouldThrowRuntimeExceptionOnButtonClick(){
//given
Button button = new Button();
// when
button.click();
// then
// look at the @Test annotation
def "should rename the file on button click"(){
given:
def button = new Button()
and:
def file = Mock(File)
button.setFile(file)
when:
button.click()
then:
1 * file.renameTo(_)
}
@Test
public void shouldRenameTheFileOnButtonClick(){
// given
Button button = new Button();
// and
File file = Mockito.mock(File.class);
button.setFile(file);
// when
button.click();
// then
Mockito.verify(file).renameTo(Matchers.anyString());
}
def "should return first element from list"(){
given:
def list = Mock(List) {
get(0) >> "First"
}
expect:
list.get(0) == "First"
}
@Test
public void shouldReturnFirstElementFromList() {
// given
List<String> list = Mockito.mock(List.class);
Mockito.when(list.get(0)).thenReturn("First");
// expect
Assert.assertEquals("First", list.get(0));
}
def "should return first element from list"(){
given:
def list = Mock(List) {
get(0) >> "First"
}
expect:
list.get(0) == "First"
}
def "maximum of two numbers"() {
expect:
Math.max(first, second) ==
result
where:
first | second | result
3 | 5 | 5
7 | 0 | 7
0 | 0 | 0
}
@Test(dataProvider = "provideNumbers")
public void maximumOfTwoNumber(int first, int second, int result)
{
Assert.assertEquals(Math.max(first, second), result);
}
@DataProvider(name = "provideNumbers")
public Object[][] provideData() {
return new Object[][] {
{ 3, 5, 5 },
{ 7, 0, 7 },
{ 0, 0, 0 }
};
}
def "should change label on button click"(){
given: "create new button"
when: "perform the click action"
then: "the label has changed"
}
def "should change label on button click"(){
given: "create new button"
def button = new Button()
when: "perform the click action"
button.click()
then: "the label has changed"
button.getLabel() == "The new label"
}
Because we have Groovy
(1..10).collect{new User()}
def "should return first element from list"(){}
new File("local.properties").text
["first", "second", "third"].each { println it
}
users.find { it.name == "Adam" }
It was Spock and Groovy
Where is Android?
Robolectric + Spock = RoboSpock
def "should show a toast on button click"(){
given:
def button = new MyButton(Robolectric.application)
when:
button.performClick()
then:
ShadowToast.textOfLatestToast =~ "Part of the toast"
}
def "should do the login action"(){
given: "create new login screen"
def loginCompoundView = new LoginCompoundView(Robolectric.application)
and: "set anonymous user"
loginCompoundView.setEmail("anonymous@email.com")
and: "mock internet connector"
loginCompoundView.apiConnector = Mock(ApiConnector)
when: "perform the login action"
loginCompoundView.performLogn()
then: "check if the title has changed"
loginCompoundView.title == "Authorisation in progress ..."
and: "the api connector has been called"
1 * loginCompoundView.apiConnector.doLogin("anonymous@email.com", _)
}
Why it is worth to try
● Groovy is colorful and funny
● Strict test format given/when/then
● Human readable as hell
● BDD
You are not losing anything
Robolectric
Based on jUnit
● Full support with Java tools like jacoco
● XML/HTML reports for CI
How to start?
Make it run with gradle
What is my first test
What should I test
Huston, we have a problem
● Robolectric configuration is not easy
● RoboSpock as well
● https://github.com/pelotasplus/RoboSpock-
tutorial
What’s next
Site to update:
www.robospock.org
Report issue:
https://github.com/robospock
QA
Przemek Jakubczyk
Senior Android Developer
Applause Inc
pjakubczyk@gmail.com
GH: pjakubczyk
Applause
We are hiring!
Please send your referrals to:
contact@applause.com

More Related Content

Similar to Robospock droidcon '14

Clojure functions
Clojure functionsClojure functions
Clojure functions
Jackson dos Santos Olveira
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181
Mahmoud Samir Fayed
 
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebBDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
Christian Baranowski
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212
Mahmoud Samir Fayed
 
Ete programs
Ete programsEte programs
Ete programs
Mayur Wankhede
 
mobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkelingmobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkeling
Devnology
 
The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.3 book - Part 43 of 88The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.3 book - Part 43 of 88
Mahmoud Samir Fayed
 
Testing a 2D Platformer with Spock
Testing a 2D Platformer with SpockTesting a 2D Platformer with Spock
Testing a 2D Platformer with Spock
Alexander Tarlinder
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
André Faria Gomes
 
Protocols
ProtocolsProtocols
Protocols
SV.CO
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
Michael Galpin
 
The Ring programming language version 1.5.3 book - Part 56 of 184
The Ring programming language version 1.5.3 book - Part 56 of 184The Ring programming language version 1.5.3 book - Part 56 of 184
The Ring programming language version 1.5.3 book - Part 56 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 36 of 88
The Ring programming language version 1.3 book - Part 36 of 88The Ring programming language version 1.3 book - Part 36 of 88
The Ring programming language version 1.3 book - Part 36 of 88
Mahmoud Samir Fayed
 
Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)
iloveallahsomuch
 
Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)
iloveallahsomuch
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdf
atulkapoor33
 
Tres Gemas De Ruby
Tres Gemas De RubyTres Gemas De Ruby
Tres Gemas De Ruby
Leonardo Soto
 

Similar to Robospock droidcon '14 (20)

Clojure functions
Clojure functionsClojure functions
Clojure functions
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181
 
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebBDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
 
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31
 
The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212
 
Ete programs
Ete programsEte programs
Ete programs
 
mobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkelingmobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkeling
 
The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.3 book - Part 43 of 88The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.3 book - Part 43 of 88
 
Testing a 2D Platformer with Spock
Testing a 2D Platformer with SpockTesting a 2D Platformer with Spock
Testing a 2D Platformer with Spock
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Protocols
ProtocolsProtocols
Protocols
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
 
The Ring programming language version 1.5.3 book - Part 56 of 184
The Ring programming language version 1.5.3 book - Part 56 of 184The Ring programming language version 1.5.3 book - Part 56 of 184
The Ring programming language version 1.5.3 book - Part 56 of 184
 
The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184
 
The Ring programming language version 1.3 book - Part 36 of 88
The Ring programming language version 1.3 book - Part 36 of 88The Ring programming language version 1.3 book - Part 36 of 88
The Ring programming language version 1.3 book - Part 36 of 88
 
Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)
 
Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdf
 
Tres Gemas De Ruby
Tres Gemas De RubyTres Gemas De Ruby
Tres Gemas De Ruby
 

More from Przemek Jakubczyk

Android Auto instrumentation
Android Auto instrumentationAndroid Auto instrumentation
Android Auto instrumentation
Przemek Jakubczyk
 
Droidcon Berlin Barcamp 2016
Droidcon Berlin Barcamp 2016Droidcon Berlin Barcamp 2016
Droidcon Berlin Barcamp 2016
Przemek Jakubczyk
 
It's always your fault. Poznań ADG 2016
It's always your fault. Poznań ADG 2016It's always your fault. Poznań ADG 2016
It's always your fault. Poznań ADG 2016
Przemek Jakubczyk
 
RoboSpock Poznań ADG 2016
RoboSpock Poznań ADG 2016RoboSpock Poznań ADG 2016
RoboSpock Poznań ADG 2016
Przemek Jakubczyk
 
It's always your fault
It's always your faultIt's always your fault
It's always your fault
Przemek Jakubczyk
 
RoboSpock
RoboSpockRoboSpock
How to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android appHow to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android app
Przemek Jakubczyk
 
How to recognise that the user has just uninstalled your android app droidc...
How to recognise that the user has just uninstalled your android app   droidc...How to recognise that the user has just uninstalled your android app   droidc...
How to recognise that the user has just uninstalled your android app droidc...
Przemek Jakubczyk
 
Uninstall opera
Uninstall operaUninstall opera
Uninstall opera
Przemek Jakubczyk
 
Android accounts & sync
Android accounts & syncAndroid accounts & sync
Android accounts & sync
Przemek Jakubczyk
 

More from Przemek Jakubczyk (10)

Android Auto instrumentation
Android Auto instrumentationAndroid Auto instrumentation
Android Auto instrumentation
 
Droidcon Berlin Barcamp 2016
Droidcon Berlin Barcamp 2016Droidcon Berlin Barcamp 2016
Droidcon Berlin Barcamp 2016
 
It's always your fault. Poznań ADG 2016
It's always your fault. Poznań ADG 2016It's always your fault. Poznań ADG 2016
It's always your fault. Poznań ADG 2016
 
RoboSpock Poznań ADG 2016
RoboSpock Poznań ADG 2016RoboSpock Poznań ADG 2016
RoboSpock Poznań ADG 2016
 
It's always your fault
It's always your faultIt's always your fault
It's always your fault
 
RoboSpock
RoboSpockRoboSpock
RoboSpock
 
How to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android appHow to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android app
 
How to recognise that the user has just uninstalled your android app droidc...
How to recognise that the user has just uninstalled your android app   droidc...How to recognise that the user has just uninstalled your android app   droidc...
How to recognise that the user has just uninstalled your android app droidc...
 
Uninstall opera
Uninstall operaUninstall opera
Uninstall opera
 
Android accounts & sync
Android accounts & syncAndroid accounts & sync
Android accounts & sync
 

Recently uploaded

openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 

Recently uploaded (20)

openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 

Robospock droidcon '14

  • 1. Applause www.applause.com ❏ Crowd Testing ❏ Beta Distributions ❏ Crash Reports ❏ Application Analytics ❏ We’re hiring!
  • 2. Przemek Jakubczyk Senior Android Developer Applause Inc pjakubczyk@gmail.com GH: pjakubczyk
  • 4. def "should change label on button click"(){ given: def button = new Button() when: button.click() then: button.getLabel() == "The new label" }
  • 5. def "should change label on button click"(){ given: def button = new Button() when: button.click() then: button.getLabel() == "The new label" } @Test public void shouldChangeLabelOnButtonClick(){ //given Button button = new Button(); // when button.click(); // then Assert.assertEquals("The new label", button.getLabel()); }
  • 6. def "should throw RuntimeException on button click"(){ given: def button = new Button() when: button.click() then: thrown(RuntimeException) }
  • 7. def "should throw RuntimeException on button click"(){ given: def button = new Button() when: button.click() then: thrown(RuntimeException) } @Test(expected = RuntimeException.class) public void shouldThrowRuntimeExceptionOnButtonClick(){ //given Button button = new Button(); // when button.click(); // then // look at the @Test annotation
  • 8. def "should rename the file on button click"(){ given: def button = new Button() and: def file = Mock(File) button.setFile(file) when: button.click() then: 1 * file.renameTo(_) }
  • 9. @Test public void shouldRenameTheFileOnButtonClick(){ // given Button button = new Button(); // and File file = Mockito.mock(File.class); button.setFile(file); // when button.click(); // then Mockito.verify(file).renameTo(Matchers.anyString()); }
  • 10. def "should return first element from list"(){ given: def list = Mock(List) { get(0) >> "First" } expect: list.get(0) == "First" }
  • 11. @Test public void shouldReturnFirstElementFromList() { // given List<String> list = Mockito.mock(List.class); Mockito.when(list.get(0)).thenReturn("First"); // expect Assert.assertEquals("First", list.get(0)); } def "should return first element from list"(){ given: def list = Mock(List) { get(0) >> "First" } expect: list.get(0) == "First" }
  • 12. def "maximum of two numbers"() { expect: Math.max(first, second) == result where: first | second | result 3 | 5 | 5 7 | 0 | 7 0 | 0 | 0 }
  • 13. @Test(dataProvider = "provideNumbers") public void maximumOfTwoNumber(int first, int second, int result) { Assert.assertEquals(Math.max(first, second), result); } @DataProvider(name = "provideNumbers") public Object[][] provideData() { return new Object[][] { { 3, 5, 5 }, { 7, 0, 7 }, { 0, 0, 0 } }; }
  • 14. def "should change label on button click"(){ given: "create new button" when: "perform the click action" then: "the label has changed" }
  • 15. def "should change label on button click"(){ given: "create new button" def button = new Button() when: "perform the click action" button.click() then: "the label has changed" button.getLabel() == "The new label" }
  • 16. Because we have Groovy (1..10).collect{new User()} def "should return first element from list"(){} new File("local.properties").text ["first", "second", "third"].each { println it } users.find { it.name == "Adam" }
  • 17. It was Spock and Groovy
  • 19. Robolectric + Spock = RoboSpock
  • 20. def "should show a toast on button click"(){ given: def button = new MyButton(Robolectric.application) when: button.performClick() then: ShadowToast.textOfLatestToast =~ "Part of the toast" }
  • 21. def "should do the login action"(){ given: "create new login screen" def loginCompoundView = new LoginCompoundView(Robolectric.application) and: "set anonymous user" loginCompoundView.setEmail("anonymous@email.com") and: "mock internet connector" loginCompoundView.apiConnector = Mock(ApiConnector) when: "perform the login action" loginCompoundView.performLogn() then: "check if the title has changed" loginCompoundView.title == "Authorisation in progress ..." and: "the api connector has been called" 1 * loginCompoundView.apiConnector.doLogin("anonymous@email.com", _) }
  • 22. Why it is worth to try ● Groovy is colorful and funny ● Strict test format given/when/then ● Human readable as hell ● BDD
  • 23. You are not losing anything Robolectric Based on jUnit ● Full support with Java tools like jacoco ● XML/HTML reports for CI
  • 24. How to start? Make it run with gradle What is my first test What should I test
  • 25. Huston, we have a problem ● Robolectric configuration is not easy ● RoboSpock as well ● https://github.com/pelotasplus/RoboSpock- tutorial
  • 26. What’s next Site to update: www.robospock.org Report issue: https://github.com/robospock
  • 27. QA Przemek Jakubczyk Senior Android Developer Applause Inc pjakubczyk@gmail.com GH: pjakubczyk
  • 28. Applause We are hiring! Please send your referrals to: contact@applause.com

Editor's Notes

  1. Mock is the star
  2. Those are v. simple Mockito samples
  3. BDD, tests can have descriptions
  4. Groovy setters
  5. I already have application ? What to do