Your SlideShare is downloading. ×
0
Robolectric Survival Guide
eBuddy• 2009 Chat (IM)• 2011 XMS• 2012 We started with RobolectricANDROID PRODUCTS HISTORY
Android!
Relationships•   Java•   Maven•   Android•   Unit tests
First Android JUnit Testimport org.junit.Before;import org.junit.Test;import static org.fest.assertions.api.Assertions.ass...
First Android JUnit Test
Android Testing Options•   No tests•   POJO•   Instrumental tests•   Android sources•   Mock Android•   Robolectric!
What is inside• Parses resources• Intercepts loading Android  classes• Rewrites method bodies  with Javassist• Binds shado...
First Robolectric Test
Key Points from Demo #1• Correct path to SDK in the  local.properties• JUnit dependency before  Android (IntelliJ IDEA)• @...
Biggest Issue of Robolectric •   Lack of documentation •   Not many examples •   Unscheduled releases •   http://robolectr...
Robolectric Drawbacks• Sometimes magic• PowerMock integration• Time of run for the first test
Shadowing• http://robolectric.blogspot.nl/2  011/01/how-to-create-your-  own-shadow-classes.html• Bind shadow class• Use o...
Dependency Injection
RoboGuice 2.0public class MainActivity extends RoboActivity implements View.OnClickListener{    @Inject Bus bus;    @Overr...
RoboGuice 2.0
Key Points from Demo #2• InjectingTestRunner• Own AbstractModule  implementation• Run injections before  every test method
Android Real Jar (Robolectric 2.0)• http://robolectric.blogspot.nl  /2011/08/using-robolectric-  with-real-android.html• R...
Robolectric or not Robolectric• Not a question for me• Follow industry
Thank you!
Upcoming SlideShare
Loading in...5
×

Robolectric Adventure

1,280

Published on

My Robolectric overview done on Android meet-up hosted by Xebia

The final code from the presentation with additional examples will be here:
https://github.com/emartynov/robolectric-presentation

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,280
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
18
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Robolectric Adventure"

  1. 1. Robolectric Survival Guide
  2. 2. eBuddy• 2009 Chat (IM)• 2011 XMS• 2012 We started with RobolectricANDROID PRODUCTS HISTORY
  3. 3. Android!
  4. 4. Relationships• Java• Maven• Android• Unit tests
  5. 5. First Android JUnit Testimport org.junit.Before;import org.junit.Test;import static org.fest.assertions.api.Assertions.assertThat;public class MainActivityTest { private MainActivity activity; @Before public void setUp () throws Exception { activity = new MainActivity(); activity.onCreate( null ); } @Test public void checkInitialTexts () throws Exception { assertThat( activity.downloadButton.getText() ).isEqualTo( "Download" ); }}
  6. 6. First Android JUnit Test
  7. 7. Android Testing Options• No tests• POJO• Instrumental tests• Android sources• Mock Android• Robolectric!
  8. 8. What is inside• Parses resources• Intercepts loading Android classes• Rewrites method bodies with Javassist• Binds shadow objects to new Android objects• Proxies modified objects
  9. 9. First Robolectric Test
  10. 10. Key Points from Demo #1• Correct path to SDK in the local.properties• JUnit dependency before Android (IntelliJ IDEA)• @RunWith( RobolectricTestRunner.class)
  11. 11. Biggest Issue of Robolectric • Lack of documentation • Not many examples • Unscheduled releases • http://robolectric.blogspot.nl/ 2011/02/how-to-work-on- robolectric-in-parallel.html
  12. 12. Robolectric Drawbacks• Sometimes magic• PowerMock integration• Time of run for the first test
  13. 13. Shadowing• http://robolectric.blogspot.nl/2 011/01/how-to-create-your- own-shadow-classes.html• Bind shadow class• Use own Runner instead of Robolectric• (Submit pull request)
  14. 14. Dependency Injection
  15. 15. RoboGuice 2.0public class MainActivity extends RoboActivity implements View.OnClickListener{ @Inject Bus bus; @Override public void onCreate( Bundle savedInstanceState ) { bus.register( this ); } @Override public void onClick( View view ) { bus.post( new DownloadDataEvent( urlInput.getText().toString() ) ); }}
  16. 16. RoboGuice 2.0
  17. 17. Key Points from Demo #2• InjectingTestRunner• Own AbstractModule implementation• Run injections before every test method
  18. 18. Android Real Jar (Robolectric 2.0)• http://robolectric.blogspot.nl /2011/08/using-robolectric- with-real-android.html• Robolectric 2.0 alpha
  19. 19. Robolectric or not Robolectric• Not a question for me• Follow industry
  20. 20. Thank you!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×