SlideShare ist ein Scribd-Unternehmen logo
1 von 35
pjakubczyk
Przemek Jakubczyk
Android Technical Lead @Applause
@pjakubczyk
RoboSpock.org
robospock
RoboSpock
enhance Android test with Groovy
Introduction
given:
I have lots of testing tools
expect:
I want better unit test
GIVEN
JVM
jUnit
Assert
Mockito
TestNG
AssertJ
PowerMock
GIVEN
JVM
jUnit
Assert
Mockito
TestNG
AssertJ
PowerMock
GIVEN
JVM
jUnit
Assert
Mockito
TestNG
AssertJ
PowerMock
GIVEN
JVM
jUnit
Assert
Mockito
TestNG
AssertJ
PowerMock
GIVEN
Android
AndroidJUnitRunner
Espresso
Robolectric
Robotium
GIVEN
AndroidJUnitRunner
Espresso
Robolectric
Robotium
JVM vs Dalvik
Android
GIVEN
AndroidJUnitRunner
Espresso
Robolectric
Robotium
UI testing
Android
JVM
when:
I work using regular JVM
then:
I choose Spock
Android
when:
I am working with Android
then:
I choose Robolectric
Conclude
given:
I am testing Android
when:
I need easy tool
then:
I choose
RoboSpock
Robolectric + SpockRoboSpock
“to conclue”
One Robospock to rule them all
One Robospock to find them
One Robospock to bring them all and in the darkness bind them
Robospock
One Robospock to rule them all
One Robospock to find them
One Robospock to bring them all and in the darkness bind them
THEN I have organized syntax
benefits from
def “should update first letter” {
given:
def myLabel = new MyLabel(“adam”)
when:
myLabel.transform()
then:
myLabel.userName == “Adam”
}
Spock
Groovy
AND
def “should start new activity”
def “should change color when action occurred”
def “should return always top element from the stack”
def “should I care about how long test name really can be?”
benefits from Groovy
I can use human readable method names
AND
benefits from Spock
given:
def myButton = new Button(...)
and:
def listener = Mock(OnClickListener)
myButton.setOnClickListener(listener)
when:
myButton.performClick()
then:
1 * listener.onClick(myButton)
I can use powerful Mocks
AND
benefits from Spock
given:
def myLabel = new Label()
when:
myLabel.setColor(color)
then:
myLabel.getColor() == color
where:
color << [Color.RED, Color.WHITE, Color.BLUE]
I can easily check many conditions
AND
benefits from Spock
given:
def myLabel = new MyLabel()
when:
myLabel.setColor(color)
then:
myLabel.getColor() == color
where:
color << [Color.RED, Color.WHITE, Color.BLUE]
I can easily check many conditions
AND
benefits from Spock
given:
def myLabel = new Label()
when:
myLabel.setName(“James Bond”)
then:
thrown(FictionalCharacterNameException)
I can organize exceptions
And many more (>10) available on
http://spockframework.github.io/spock/docs/1.0/extensions.html
AND
benefits from Spock
@Stepwise
@Issue("http://my.issues.org/FOO-1")
@IgnoreIf(reason == "TODO")
@Timeout(5)
I can use other Spock extensions
AND
benefits from Groovy
given:
def dao = new UserDao()
and:
def users = (1..10).collect{ User.newInstance() }
then:
dao.insert(users)
where:
dao.getUserCount() == 10
I can use groovy collections
AND
benefits from Groovy
given:
def users = (1..10).collect{ User.newInstance() }
when:
def result = users.find { it.name == “James” }
then:
result.lastName == “Bond”
I can use groovy collections
AND
given:
def activity.sharedPref = Mock(SharedPreferences) {
getString(“metJamesBond”) >> false
}
when:
activity.myButton.performClick()
then:
activity.myLabel.getText() == “Sorry, you
haven’t meet James”
Benefits from Groovy
I can use closures in Mocks
THEN
Benefits from Robolectric
given:
def myLabel = new TextView(RuntimeEnvironment.application)
when:
myLabel.setText(“James Bond”)
then:
myLabel.getText() == “James Bond”
I can use Context
AND
Benefits from Robolectric
I can use helpful shadows
given:
def myButton = new Button(...)
when:
myButton.performClick()
then:
ShadowToast.lastToast
ShadowToast.textOfLastToast
== “I <3 Minsk and James Bond too”
AND
Benefits from Robolectric
I can use helpful shadows
given:
def myButton = new Button(...)
and:
def listener = new View.OnClickListener() {...}
when:
myButton.setOnClickListener(listener)
then:
Shadows.shadowOf(myButton)
.getOnClickListener() == listener
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6'
}
}
apply plugin: 'com.android.application'
apply plugin: 'groovyx.grooid.groovy-android'
dependencies {
testCompile 'org.robospock:robospock:1.0.0'
}
build.gradle
Android Studio
Android Studio
Thanks. Any Questions?
Przemek Jakubczyk
Android Technical Lead @Applause
gh: pjakubczyk
@pjakubczyk
www.robospock.org
Tips:
1. Try to create an interface between your code and OS code
a) Toasts
b) starting activity/service
2. Make a barrier from 3rd party code
for example inherit from RoboSpecfication
Because author might change package name :)

Weitere ähnliche Inhalte

Was ist angesagt?

My own preferred testing tools - Paris JUG 2011
My own preferred testing tools - Paris JUG 2011My own preferred testing tools - Paris JUG 2011
My own preferred testing tools - Paris JUG 2011
David Gageot
 

Was ist angesagt? (20)

Testing Java Microservices Devoxx be 2017
Testing Java Microservices Devoxx be 2017Testing Java Microservices Devoxx be 2017
Testing Java Microservices Devoxx be 2017
 
軟體測試是在測試什麼?
軟體測試是在測試什麼?軟體測試是在測試什麼?
軟體測試是在測試什麼?
 
Testing For Unicorns [IMWorld]
Testing For Unicorns [IMWorld] Testing For Unicorns [IMWorld]
Testing For Unicorns [IMWorld]
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 
淺談 Groovy 與 AWS 雲端應用開發整合
淺談 Groovy 與 AWS 雲端應用開發整合淺談 Groovy 與 AWS 雲端應用開發整合
淺談 Groovy 與 AWS 雲端應用開發整合
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Appcelerator Alloy MVC
Appcelerator Alloy MVCAppcelerator Alloy MVC
Appcelerator Alloy MVC
 
Escape from Mars
Escape from MarsEscape from Mars
Escape from Mars
 
Robolectric Adventure
Robolectric AdventureRobolectric Adventure
Robolectric Adventure
 
Test code that will not slow you down
Test code that will not slow you downTest code that will not slow you down
Test code that will not slow you down
 
Automated Web Testing using JavaScript
Automated Web Testing using JavaScriptAutomated Web Testing using JavaScript
Automated Web Testing using JavaScript
 
Dead-Simple Async Control Flow with Coroutines
Dead-Simple Async Control Flow with CoroutinesDead-Simple Async Control Flow with Coroutines
Dead-Simple Async Control Flow with Coroutines
 
The End of the world as we know it - AKA your last NullPointerException $1B b...
The End of the world as we know it - AKA your last NullPointerException $1B b...The End of the world as we know it - AKA your last NullPointerException $1B b...
The End of the world as we know it - AKA your last NullPointerException $1B b...
 
My own preferred testing tools - Paris JUG 2011
My own preferred testing tools - Paris JUG 2011My own preferred testing tools - Paris JUG 2011
My own preferred testing tools - Paris JUG 2011
 
Testing React Applications
Testing React ApplicationsTesting React Applications
Testing React Applications
 
Take a Stroll in the Bazaar
Take a Stroll in the BazaarTake a Stroll in the Bazaar
Take a Stroll in the Bazaar
 
AngularJS and Protractor
AngularJS and ProtractorAngularJS and Protractor
AngularJS and Protractor
 
Isomorphic React Apps Testing
Isomorphic React Apps TestingIsomorphic React Apps Testing
Isomorphic React Apps Testing
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
 
Building Native Mobile Apps using Javascript with Titanium
Building Native Mobile Apps using Javascript with TitaniumBuilding Native Mobile Apps using Javascript with Titanium
Building Native Mobile Apps using Javascript with Titanium
 

Ähnlich wie RoboSpock

Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009
Dr Nic Williams
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
Andy Peterson
 
JavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdfJavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdf
Sathwika7
 

Ähnlich wie RoboSpock (20)

Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
 
Cool JVM Tools to Help You Test
Cool JVM Tools to Help You TestCool JVM Tools to Help You Test
Cool JVM Tools to Help You Test
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
Google I/O 2021 Recap
Google I/O 2021 RecapGoogle I/O 2021 Recap
Google I/O 2021 Recap
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock Framework
 
Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009
 
Android Automation Using Robotium
Android Automation Using RobotiumAndroid Automation Using Robotium
Android Automation Using Robotium
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
Unit Testing in iOS
Unit Testing in iOSUnit Testing in iOS
Unit Testing in iOS
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
From devOps to front end Ops, test first
From devOps to front end Ops, test firstFrom devOps to front end Ops, test first
From devOps to front end Ops, test first
 
Unit test-using-spock in Grails
Unit test-using-spock in GrailsUnit test-using-spock in Grails
Unit test-using-spock in Grails
 
Automation Zaman Now
Automation Zaman NowAutomation Zaman Now
Automation Zaman Now
 
JavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdfJavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdf
 
UI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected JourneyUI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected Journey
 
Greach 2015 Spock workshop
Greach 2015 Spock workshopGreach 2015 Spock workshop
Greach 2015 Spock workshop
 
Mock your way with Mockito
Mock your way with MockitoMock your way with Mockito
Mock your way with Mockito
 
Android testing
Android testingAndroid testing
Android testing
 
From Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practiceFrom Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practice
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby
 

Mehr von 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
 

Mehr von Przemek Jakubczyk (8)

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
It's always your faultIt's always your fault
It's always your fault
 
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
 
Robospock droidcon '14
Robospock   droidcon '14Robospock   droidcon '14
Robospock droidcon '14
 

RoboSpock

Hinweis der Redaktion

  1. Połączyć Assert + AssertJ, TestNG + jUnit, PowerMock + Mockito
  2. TestNG as a convenient extension for jUnit
  3. AssertJ has an evolution of generic junit assertions
  4. Mockito and PowerMock as competitors
  5. Where are test running
  6. Those are UI testing frameworks
  7. Of cource we don’t need to test Android API
  8. Test for getters and setters
  9. Test for getters and setters
  10. Test for getters and setters
  11. in JVM foreach ….
  12. SharedPreferences is an interface
  13. controller can manipulate activity lifecycle
  14. controller can manipulate activity lifecycle
  15. Only when I have time. 45 minutes ?