Bring Back the Fun to
Testing Android Apps
with Robolectric

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
Bring Back the Fun to
Testing Android Apps
with Robolectric

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
Testing Android Apps with Robolectric

What’s the problem?
Why is Robolectric a solution?
Demo
Peter Friese - @peterfriese...
What’s the problem?

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
What’s the problem?
Running tests requires:
•

Dexing Dexing

•

Packaging Packaging

•

Installation on device / emulator...
Dexing

Packaging

Peter Friese - @peterfriese - http:/
/www.peterfriese.de

Installation
Robolectric to the rescue!
Run tests in a regular JVM, not on Dalvik VM
•

Dexing

•

Packaging

•

Installation on device...
There is another problem…

protected void onCreate(Bundle savedInstanceState) {
throw new RuntimeException("Stub!");
}

Pe...
Robolectric Solution:
Shadow Objects
•

Intercept class loading

•

Rewrite method bodies (using ASM)

•

Intercept calls ...
FEST - Readability for Your Tests
Plain JUnit:
assertEquals(View.GONE, textView.getVisibility());
!
java.lang.AssertionErr...
Demo
See http:/
/www.peterfriese.de/unit-testing-android-apps-with-robolectric-and-eclipse/ for a
step-by-step description...
Electrified? Here’s where to get Robolectric / FEST

Web: http:/
/ww.robolectric.org
Github: https:/
/github.com/robolectri...
Contact

Peter Friese



ter.friese@zuhlke.com
pe
!
td

Zuhlke Engineering L
43 Whitfield St

London

W1T 4HD

!
+44 7825 6...
Image credits

•

Snail - http:/
/www.wallsfeed.com/snail-journey-leaf/

Peter Friese - @peterfriese - http:/
/www.peterfr...
The End
Upcoming SlideShare
Loading in...5
×

Bring Back the Fun to Testing Android Apps with Robolectric

10,543

Published on

A short introduction why Robolectric will make testing more fun on Android and how to set it up in Eclipse.

Published in: Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
10,543
On Slideshare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
Downloads
16
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Bring Back the Fun to Testing Android Apps with Robolectric

  1. 1. Bring Back the Fun to Testing Android Apps with Robolectric Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  2. 2. Bring Back the Fun to Testing Android Apps with Robolectric Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  3. 3. Testing Android Apps with Robolectric What’s the problem? Why is Robolectric a solution? Demo Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  4. 4. What’s the problem? Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  5. 5. What’s the problem? Running tests requires: • Dexing Dexing • Packaging Packaging • Installation on device / emulator Installation Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  6. 6. Dexing Packaging Peter Friese - @peterfriese - http:/ /www.peterfriese.de Installation
  7. 7. Robolectric to the rescue! Run tests in a regular JVM, not on Dalvik VM • Dexing • Packaging • Installation on device / emulator Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  8. 8. There is another problem… protected void onCreate(Bundle savedInstanceState) { throw new RuntimeException("Stub!"); } Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  9. 9. Robolectric Solution: Shadow Objects • Intercept class loading • Rewrite method bodies (using ASM) • Intercept calls to Android classes, record state in shadow classes Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  10. 10. FEST - Readability for Your Tests Plain JUnit: assertEquals(View.GONE, textView.getVisibility()); ! java.lang.AssertionError: expected:<8> but was:<0> FEST: assertThat(textView).isGone(); ! java.lang.AssertionError: Expected to be gone but was visible Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  11. 11. Demo See http:/ /www.peterfriese.de/unit-testing-android-apps-with-robolectric-and-eclipse/ for a step-by-step description of how to set up Robolectric in Eclipse Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  12. 12. Electrified? Here’s where to get Robolectric / FEST Web: http:/ /ww.robolectric.org Github: https:/ /github.com/robolectric/robolectric Peter Friese - @peterfriese - http:/ /www.peterfriese.de Web: http:/ /square.github.io/fest-android/ Github: https:/ /github.com/square/fest-android
  13. 13. Contact Peter Friese ter.friese@zuhlke.com pe ! td Zuhlke Engineering L 43 Whitfield St London W1T 4HD ! +44 7825 688 244 Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  14. 14. Image credits • Snail - http:/ /www.wallsfeed.com/snail-journey-leaf/ Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  15. 15. The End
  1. Gostou de algum slide específico?

    Recortar slides é uma maneira fácil de colecionar informações para acessar mais tarde.

×