SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
Unit Testing
with Robolectric	
DroidCon Berlin	
Danny Preussler, ebay Kleinanzeigen
•  Since 2012 Lead Engineer Android @
ebay Kleinanzeigen	
•  Before Team Lead Mobile Enterprise
Solutions @ Cortado	
•  C++ Developer @ PSI AG	
•  Started career as developer @ Alcatel	
•  articles in: android360, mobile Technology,
Java Magazin	
•  speaker: Blackberry Developer Conference SF,
DroidCons 	
Believe in mobile	
who's that guy?
eBay Kleinanzeigen
Android app:
	
• free app	
• 2 Mio downloads	
• 176 K Daily UV	
• 4.1/5 stars
(>6K ratings)
SOLID 	
FOUNDATION	
Flughafen Berlin-Brandenburg, Blick in die Abflughalle by Muns CC BY 3.0
http://commons.wikimedia.org/wiki/File:120513-BER-innen.JPG
Raus aus der Garage!	
Tidy garage by Bryn Pinzgauer CC 2.0
http://www."ickr.com/photos/12394349@N06/4492572621/in/photostream/
• Junit 4
(out for 6+ years!!)	
• Use all your
utilities
(i.e. mocking)	
• Use your coverage
framework	
• Use CI tools
without Android
plugins (sonar)	
Scyscrapers by elminium, CC 2.0 http://www."ickr.com/photos/lumen850/5461476268/in/
photostream/
Pure JUnit?	
java.lang.RuntimeException: Stub! 	
Android Firewall by Uncalno, CC BY 2.0 "ickr.com/photos/uncalno/8538679708
Separate Java and Android Code?	
• Android is not Java!	
	
• Intent, Bundle,
SparseArray, Uri.. not
fancy device classes!	
	
• Context everywhere	
	
• Recreate the
System! (interface
UI {...} ?)	
Great Wall of China (IV) by isawnyu. CC 2.0 http://
www."ickr.com/photos/isawnyu/7183821643/in/
photostream/
Allows loading of Android Classes
in pure Java projects
static Intent createIntent(Context context, String query,
String value) {
Intent i = new Intent(context, AdListActivity.class);
i.putExtra(AppConstants.QUERY, query);
i.putExtra(AppConstants.VALUE, queryString);
return i;
}
@Test
public void createIntentForQuery() {
Context c = new AdListActivity();
Intent intent =
MyActivity.createIntent(c, "key", "value");
assertNotNull(intent);
}
In practice (with programs of several thousand lines of
code), we haven't discovered any signi!cant di"erences
between the two VMs, and we would consider any
di"erence to be a bug in one or the other VM.“ 
https://sites.google.com/site/androiddevtesting/ 	
Is this valid?
static Intent createIntent(Context context, String query,
String value) {
Intent i = new Intent(context, AdListActivity.class);
i.putExtra(AppConstants.QUERY, query);
i.putExtra(AppConstants.VALUE, queryString);
return i;
}
@Test
public void createIntentForQuery() {
Context c = mock(Context.class);
Intent intent =
MyActivity.createIntent(c, "key", "value");
assertNotNull(intent);
}
what's this mock thing?
Martin Fowler:
„test-doubles ... pre-programmed with
expectations “
mocks...	
TelephonyManager mgr =
mock(TelephonyManager.class);
when(mgr.getDeviceId()).thenReturn("123456");
...
verify(mgr).getDevice();and/or
verifyNoMoreInteractions(mgr);
MyPreferences pref = spy(new MyPreferences(ctx))
...
spys...	
verify(pref).saveTitle(same(title));
verify(pref).savePersonalData(anyString());
Let’s do some Magic…	
magic by digitlizedchaos, CC 2.0
"ickr.com/photos/digitizedchaos/4889987210/
in/photostream/
@Test
public void checkPhoneNumberIsHidden() {
MyActivity activity = new MyActivity();
activity.onCreate();
TextView tv = (TextView)
activity.findViewById(R.id.callText);
assertEquals(View.GONE, tv.getVisibility());
}
long shadows by Matthew Photography CC 2.0 "ickr.com/photos/
21560098@N06/8064387720/in/photostream/	
let's talk about shadows...
Dead End - mid by bennylin0724, CC BY 2.0
flickr.com/photos/benny_lin/191393604
2.0
2.0	
@Test @Values(qualifiers = "fr-land")
public void
shouldShowBucolicFrenchLandscape() throws
Exception {
// ...
}
•  less shadows, more real code
(goal is to remove 99% of shadows)	
•  since alpha2: support package complete shadow free	
•  aims for sherlock supported, library support	
•  performance boost 	
•  Value quali$ers:
Thank you 	
for coming!	
dpreussler@ebay.com
Wanna work with us?	
eBay Kleinanzeigen
http://goo.gl/3GCJk	
mobile.de
http://goo.gl/JYsXM

Contenu connexe

Tendances

Android code puzzlers + tips & tricks
Android code puzzlers + tips & tricksAndroid code puzzlers + tips & tricks
Android code puzzlers + tips & tricks
NLJUG
 
Androidの本当にあった怖い話
Androidの本当にあった怖い話Androidの本当にあった怖い話
Androidの本当にあった怖い話
Yusuke Yamamoto
 

Tendances (20)

Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++
 
Performance #1: Memory
Performance #1: MemoryPerformance #1: Memory
Performance #1: Memory
 
Code to DI For - Dependency Injection for Modern Applications
Code to DI For - Dependency Injection for Modern ApplicationsCode to DI For - Dependency Injection for Modern Applications
Code to DI For - Dependency Injection for Modern Applications
 
droidparts
droidpartsdroidparts
droidparts
 
Android TDD
Android TDDAndroid TDD
Android TDD
 
My way to clean android V2
My way to clean android V2My way to clean android V2
My way to clean android V2
 
Android code puzzlers + tips & tricks
Android code puzzlers + tips & tricksAndroid code puzzlers + tips & tricks
Android code puzzlers + tips & tricks
 
My way to clean android v2 English DroidCon Spain
My way to clean android v2 English DroidCon SpainMy way to clean android v2 English DroidCon Spain
My way to clean android v2 English DroidCon Spain
 
The Ring programming language version 1.8 book - Part 77 of 202
The Ring programming language version 1.8 book - Part 77 of 202The Ring programming language version 1.8 book - Part 77 of 202
The Ring programming language version 1.8 book - Part 77 of 202
 
The Ring programming language version 1.7 book - Part 75 of 196
The Ring programming language version 1.7 book - Part 75 of 196The Ring programming language version 1.7 book - Part 75 of 196
The Ring programming language version 1.7 book - Part 75 of 196
 
Androidの本当にあった怖い話
Androidの本当にあった怖い話Androidの本当にあった怖い話
Androidの本当にあった怖い話
 
The Screenplay Pattern: Better Interactions for Better Automation
The Screenplay Pattern: Better Interactions for Better AutomationThe Screenplay Pattern: Better Interactions for Better Automation
The Screenplay Pattern: Better Interactions for Better Automation
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
 
少し幸せになる技術
少し幸せになる技術少し幸せになる技術
少し幸せになる技術
 
Agile Android
Agile AndroidAgile Android
Agile Android
 
My way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca editionMy way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca edition
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
 
Quickly Testing Qt Desktop Applications
Quickly Testing Qt Desktop ApplicationsQuickly Testing Qt Desktop Applications
Quickly Testing Qt Desktop Applications
 
Hacking pokemon go [droidcon tel aviv 2016]
Hacking pokemon go [droidcon tel aviv 2016]Hacking pokemon go [droidcon tel aviv 2016]
Hacking pokemon go [droidcon tel aviv 2016]
 
CDI: How do I ?
CDI: How do I ?CDI: How do I ?
CDI: How do I ?
 

Similaire à Android Unit Testing With Robolectric

Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
NgLQun
 
Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talk
Imam Raza
 
Testing and Building Android
Testing and Building AndroidTesting and Building Android
Testing and Building Android
Droidcon Berlin
 

Similaire à Android Unit Testing With Robolectric (20)

Rockstar Android Testing (Mobile TechCon Munich 2014)
Rockstar Android Testing (Mobile TechCon Munich 2014)Rockstar Android Testing (Mobile TechCon Munich 2014)
Rockstar Android Testing (Mobile TechCon Munich 2014)
 
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
 
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
 
Android class provider in mumbai
Android class provider in mumbaiAndroid class provider in mumbai
Android class provider in mumbai
 
Xamarin.Android Introduction
Xamarin.Android IntroductionXamarin.Android Introduction
Xamarin.Android Introduction
 
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
 
apidays LIVE Paris - Automation API Testing by Guillaume Jeannic
apidays LIVE Paris - Automation API Testing by Guillaume Jeannicapidays LIVE Paris - Automation API Testing by Guillaume Jeannic
apidays LIVE Paris - Automation API Testing by Guillaume Jeannic
 
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
 
Appium overview
Appium overviewAppium overview
Appium overview
 
Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talk
 
Visual Studio 2017 Launch Event
Visual Studio 2017 Launch EventVisual Studio 2017 Launch Event
Visual Studio 2017 Launch Event
 
Testing and Building Android
Testing and Building AndroidTesting and Building Android
Testing and Building Android
 
Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...
Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...
Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callande...
 
React native: building shared components for Android and iOS
React native: building shared components for Android and iOSReact native: building shared components for Android and iOS
React native: building shared components for Android and iOS
 
Playing with parse.com
Playing with parse.comPlaying with parse.com
Playing with parse.com
 
Using Xamarin for your Mobile +Apps - Xamarin Experience 2017
Using Xamarin for your Mobile +Apps - Xamarin Experience 2017Using Xamarin for your Mobile +Apps - Xamarin Experience 2017
Using Xamarin for your Mobile +Apps - Xamarin Experience 2017
 
MongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDBMongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDB
 
Introduction to xamarin
Introduction to xamarinIntroduction to xamarin
Introduction to xamarin
 
Can We Deliver Mobile Apps Continuously?
Can We Deliver Mobile Apps Continuously?Can We Deliver Mobile Apps Continuously?
Can We Deliver Mobile Apps Continuously?
 
ITCamp 2018 - Dan Ardelean - CI/CD for mobile development using Visual Studio...
ITCamp 2018 - Dan Ardelean - CI/CD for mobile development using Visual Studio...ITCamp 2018 - Dan Ardelean - CI/CD for mobile development using Visual Studio...
ITCamp 2018 - Dan Ardelean - CI/CD for mobile development using Visual Studio...
 

Plus de Danny Preussler

Plus de Danny Preussler (14)

We aint got no time - Droidcon Nairobi
We aint got no time - Droidcon NairobiWe aint got no time - Droidcon Nairobi
We aint got no time - Droidcon Nairobi
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
TDD on android. Why and How? (Coding Serbia 2019)
TDD on android. Why and How? (Coding Serbia 2019)TDD on android. Why and How? (Coding Serbia 2019)
TDD on android. Why and How? (Coding Serbia 2019)
 
TDD on Android (Øredev 2018)
TDD on Android (Øredev 2018)TDD on Android (Øredev 2018)
TDD on Android (Øredev 2018)
 
Junit5: the next gen of testing, don't stay behind
Junit5: the next gen of testing, don't stay behindJunit5: the next gen of testing, don't stay behind
Junit5: the next gen of testing, don't stay behind
 
Demystifying dependency Injection: Dagger and Toothpick
Demystifying dependency Injection: Dagger and ToothpickDemystifying dependency Injection: Dagger and Toothpick
Demystifying dependency Injection: Dagger and Toothpick
 
Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016
Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016
Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016
 
Unit testing without Robolectric, Droidcon Berlin 2016
Unit testing without Robolectric, Droidcon Berlin 2016Unit testing without Robolectric, Droidcon Berlin 2016
Unit testing without Robolectric, Droidcon Berlin 2016
 
15 tips to improve your unit tests (Droidcon Berlin 2016 Barcamp)
15 tips to improve your unit tests (Droidcon Berlin 2016 Barcamp)15 tips to improve your unit tests (Droidcon Berlin 2016 Barcamp)
15 tips to improve your unit tests (Droidcon Berlin 2016 Barcamp)
 
All around the world, localization and internationalization on Android (Droid...
All around the world, localization and internationalization on Android (Droid...All around the world, localization and internationalization on Android (Droid...
All around the world, localization and internationalization on Android (Droid...
 
(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016
(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016
(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016
 
Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014
Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014
Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014
 
Abgeschottete Realität - Testen im Emulator, Mobile Testing Days 2014, Berlin
Abgeschottete Realität - Testen im Emulator, Mobile Testing Days 2014, BerlinAbgeschottete Realität - Testen im Emulator, Mobile Testing Days 2014, Berlin
Abgeschottete Realität - Testen im Emulator, Mobile Testing Days 2014, Berlin
 
Android Code Puzzles (DroidCon Amsterdam 2012)
Android Code Puzzles (DroidCon Amsterdam 2012)Android Code Puzzles (DroidCon Amsterdam 2012)
Android Code Puzzles (DroidCon Amsterdam 2012)
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Android Unit Testing With Robolectric

  • 1. Unit Testing with Robolectric DroidCon Berlin Danny Preussler, ebay Kleinanzeigen
  • 2. •  Since 2012 Lead Engineer Android @ ebay Kleinanzeigen •  Before Team Lead Mobile Enterprise Solutions @ Cortado •  C++ Developer @ PSI AG •  Started career as developer @ Alcatel •  articles in: android360, mobile Technology, Java Magazin •  speaker: Blackberry Developer Conference SF, DroidCons Believe in mobile who's that guy?
  • 3. eBay Kleinanzeigen Android app: • free app • 2 Mio downloads • 176 K Daily UV • 4.1/5 stars (>6K ratings)
  • 4. SOLID FOUNDATION Flughafen Berlin-Brandenburg, Blick in die Abflughalle by Muns CC BY 3.0 http://commons.wikimedia.org/wiki/File:120513-BER-innen.JPG
  • 5. Raus aus der Garage! Tidy garage by Bryn Pinzgauer CC 2.0 http://www."ickr.com/photos/12394349@N06/4492572621/in/photostream/
  • 6. • Junit 4 (out for 6+ years!!) • Use all your utilities (i.e. mocking) • Use your coverage framework • Use CI tools without Android plugins (sonar) Scyscrapers by elminium, CC 2.0 http://www."ickr.com/photos/lumen850/5461476268/in/ photostream/
  • 7. Pure JUnit? java.lang.RuntimeException: Stub! Android Firewall by Uncalno, CC BY 2.0 "ickr.com/photos/uncalno/8538679708
  • 8. Separate Java and Android Code? • Android is not Java! • Intent, Bundle, SparseArray, Uri.. not fancy device classes! • Context everywhere • Recreate the System! (interface UI {...} ?) Great Wall of China (IV) by isawnyu. CC 2.0 http:// www."ickr.com/photos/isawnyu/7183821643/in/ photostream/
  • 9. Allows loading of Android Classes in pure Java projects
  • 10. static Intent createIntent(Context context, String query, String value) { Intent i = new Intent(context, AdListActivity.class); i.putExtra(AppConstants.QUERY, query); i.putExtra(AppConstants.VALUE, queryString); return i; } @Test public void createIntentForQuery() { Context c = new AdListActivity(); Intent intent = MyActivity.createIntent(c, "key", "value"); assertNotNull(intent); }
  • 11. In practice (with programs of several thousand lines of code), we haven't discovered any signi!cant di"erences between the two VMs, and we would consider any di"erence to be a bug in one or the other VM.“  https://sites.google.com/site/androiddevtesting/ Is this valid?
  • 12. static Intent createIntent(Context context, String query, String value) { Intent i = new Intent(context, AdListActivity.class); i.putExtra(AppConstants.QUERY, query); i.putExtra(AppConstants.VALUE, queryString); return i; } @Test public void createIntentForQuery() { Context c = mock(Context.class); Intent intent = MyActivity.createIntent(c, "key", "value"); assertNotNull(intent); }
  • 13. what's this mock thing? Martin Fowler: „test-doubles ... pre-programmed with expectations “
  • 15. MyPreferences pref = spy(new MyPreferences(ctx)) ... spys... verify(pref).saveTitle(same(title)); verify(pref).savePersonalData(anyString());
  • 16. Let’s do some Magic… magic by digitlizedchaos, CC 2.0 "ickr.com/photos/digitizedchaos/4889987210/ in/photostream/
  • 17. @Test public void checkPhoneNumberIsHidden() { MyActivity activity = new MyActivity(); activity.onCreate(); TextView tv = (TextView) activity.findViewById(R.id.callText); assertEquals(View.GONE, tv.getVisibility()); }
  • 18. long shadows by Matthew Photography CC 2.0 "ickr.com/photos/ 21560098@N06/8064387720/in/photostream/ let's talk about shadows...
  • 19. Dead End - mid by bennylin0724, CC BY 2.0 flickr.com/photos/benny_lin/191393604
  • 20. 2.0
  • 21. 2.0 @Test @Values(qualifiers = "fr-land") public void shouldShowBucolicFrenchLandscape() throws Exception { // ... } •  less shadows, more real code (goal is to remove 99% of shadows) •  since alpha2: support package complete shadow free •  aims for sherlock supported, library support •  performance boost •  Value quali$ers:
  • 22. Thank you for coming! dpreussler@ebay.com
  • 23. Wanna work with us? eBay Kleinanzeigen http://goo.gl/3GCJk mobile.de http://goo.gl/JYsXM