SlideShare a Scribd company logo
1 of 20
Robolectric Survival Guide
eBuddy
• 2009 Chat (IM)
• 2011 XMS
• 2012 We started with Robolectric




ANDROID PRODUCTS HISTORY
Android!
Relationships
•   Java
•   Maven
•   Android
•   Unit tests
First Android JUnit Test
import 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" );
    }
}
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 shadow objects to
  new Android objects
• Proxies modified objects
First Robolectric Test
Key Points from Demo #1
• Correct path to SDK in the
  local.properties
• JUnit dependency before
  Android (IntelliJ IDEA)
• @RunWith(
  RobolectricTestRunner.class)
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
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 own Runner instead of
  Robolectric
• (Submit pull request)
Dependency Injection
RoboGuice 2.0

public 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() ) );
    }
}
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
• Robolectric 2.0 alpha
Robolectric or not Robolectric
• Not a question for me
• Follow industry
Thank you!

More Related Content

What's hot

Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014Oren Rubin
 
XCUITest for iOS App Testing and how to test with Xcode
XCUITest for iOS App Testing and how to test with XcodeXCUITest for iOS App Testing and how to test with Xcode
XCUITest for iOS App Testing and how to test with XcodepCloudy
 
Secret unit testing tools
Secret unit testing toolsSecret unit testing tools
Secret unit testing toolsDror Helper
 
Android Building, Testing and reversing
Android Building, Testing and reversingAndroid Building, Testing and reversing
Android Building, Testing and reversingEnrique López Mañas
 
Ten Minutes To Tellurium
Ten Minutes To TelluriumTen Minutes To Tellurium
Ten Minutes To TelluriumJohn.Jian.Fang
 
Singleton Object Management
Singleton Object ManagementSingleton Object Management
Singleton Object Managementppd1961
 
基於 Flow & Path 的 MVP 架構
基於 Flow & Path 的 MVP 架構基於 Flow & Path 的 MVP 架構
基於 Flow & Path 的 MVP 架構玄武 Wu
 
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...Alan Richardson
 
Automated Xcode 7 UI Testing
Automated Xcode 7 UI TestingAutomated Xcode 7 UI Testing
Automated Xcode 7 UI TestingJouni Miettunen
 
A journey beyond the page object pattern
A journey beyond the page object patternA journey beyond the page object pattern
A journey beyond the page object patternRiverGlide
 
Builda responsivetypescriptwebdriverio framework
Builda responsivetypescriptwebdriverio frameworkBuilda responsivetypescriptwebdriverio framework
Builda responsivetypescriptwebdriverio frameworkWim Selles
 
Selenium - The page object pattern
Selenium - The page object patternSelenium - The page object pattern
Selenium - The page object patternMichael Palotas
 
React native: building native iOS apps with javascript
React native: building native iOS apps with javascriptReact native: building native iOS apps with javascript
React native: building native iOS apps with javascriptPolidea
 
Writing Android Libraries
Writing Android LibrariesWriting Android Libraries
Writing Android Librariesemanuelez
 
Automation Abstractions: Page Objects and Beyond
Automation Abstractions: Page Objects and BeyondAutomation Abstractions: Page Objects and Beyond
Automation Abstractions: Page Objects and BeyondTechWell
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React AppAll Things Open
 

What's hot (17)

Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014
 
XCUITest for iOS App Testing and how to test with Xcode
XCUITest for iOS App Testing and how to test with XcodeXCUITest for iOS App Testing and how to test with Xcode
XCUITest for iOS App Testing and how to test with Xcode
 
Secret unit testing tools
Secret unit testing toolsSecret unit testing tools
Secret unit testing tools
 
Android Building, Testing and reversing
Android Building, Testing and reversingAndroid Building, Testing and reversing
Android Building, Testing and reversing
 
Ten Minutes To Tellurium
Ten Minutes To TelluriumTen Minutes To Tellurium
Ten Minutes To Tellurium
 
Singleton Object Management
Singleton Object ManagementSingleton Object Management
Singleton Object Management
 
基於 Flow & Path 的 MVP 架構
基於 Flow & Path 的 MVP 架構基於 Flow & Path 的 MVP 架構
基於 Flow & Path 的 MVP 架構
 
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
 
Automated Xcode 7 UI Testing
Automated Xcode 7 UI TestingAutomated Xcode 7 UI Testing
Automated Xcode 7 UI Testing
 
crashing in style
crashing in stylecrashing in style
crashing in style
 
A journey beyond the page object pattern
A journey beyond the page object patternA journey beyond the page object pattern
A journey beyond the page object pattern
 
Builda responsivetypescriptwebdriverio framework
Builda responsivetypescriptwebdriverio frameworkBuilda responsivetypescriptwebdriverio framework
Builda responsivetypescriptwebdriverio framework
 
Selenium - The page object pattern
Selenium - The page object patternSelenium - The page object pattern
Selenium - The page object pattern
 
React native: building native iOS apps with javascript
React native: building native iOS apps with javascriptReact native: building native iOS apps with javascript
React native: building native iOS apps with javascript
 
Writing Android Libraries
Writing Android LibrariesWriting Android Libraries
Writing Android Libraries
 
Automation Abstractions: Page Objects and Beyond
Automation Abstractions: Page Objects and BeyondAutomation Abstractions: Page Objects and Beyond
Automation Abstractions: Page Objects and Beyond
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
 

Viewers also liked

My summer experience with the future
My summer experience with the futureMy summer experience with the future
My summer experience with the futureYashiro Anazawa
 
Android Brown Bag Lunch - DroidconNL overview
Android Brown Bag Lunch - DroidconNL overviewAndroid Brown Bag Lunch - DroidconNL overview
Android Brown Bag Lunch - DroidconNL overviewEugen Martynov
 
Organisasi belajar mendunia
Organisasi belajar menduniaOrganisasi belajar mendunia
Organisasi belajar menduniaZulrahmat Togala
 

Viewers also liked (6)

Animals test
Animals testAnimals test
Animals test
 
My summer experience with the future
My summer experience with the futureMy summer experience with the future
My summer experience with the future
 
Android Brown Bag Lunch - DroidconNL overview
Android Brown Bag Lunch - DroidconNL overviewAndroid Brown Bag Lunch - DroidconNL overview
Android Brown Bag Lunch - DroidconNL overview
 
Organisasi belajar mendunia
Organisasi belajar menduniaOrganisasi belajar mendunia
Organisasi belajar mendunia
 
Facebook Stetho
Facebook StethoFacebook Stetho
Facebook Stetho
 
Template project
Template projectTemplate project
Template project
 

Similar to Robolectric Adventure

Robotium framework & Jenkins CI tools - TdT@Cluj #19
Robotium framework & Jenkins CI tools - TdT@Cluj #19Robotium framework & Jenkins CI tools - TdT@Cluj #19
Robotium framework & Jenkins CI tools - TdT@Cluj #19Tabăra de Testare
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationRichard North
 
Guide to the jungle of testing frameworks
Guide to the jungle of testing frameworksGuide to the jungle of testing frameworks
Guide to the jungle of testing frameworksTomáš Kypta
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android ApplicationsRody Middelkoop
 
Mockito a simple, intuitive mocking framework
Mockito   a simple, intuitive mocking frameworkMockito   a simple, intuitive mocking framework
Mockito a simple, intuitive mocking frameworkPhat VU
 
Introduction to AndroidMock
Introduction to AndroidMockIntroduction to AndroidMock
Introduction to AndroidMockLi-Wei Cheng
 
Building Top-Notch Androids SDKs
Building Top-Notch Androids SDKsBuilding Top-Notch Androids SDKs
Building Top-Notch Androids SDKsrelayr
 
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)Danny Preussler
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsEffie Arditi
 
Mobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileMobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileKonstantin Loginov
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQueryGill Cleeren
 
Chegg - iOS @ Scale
Chegg - iOS @ ScaleChegg - iOS @ Scale
Chegg - iOS @ ScaleAviel Lazar
 
Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​Payara
 
Android Meetup Slovenija #3 - Testing with Robolectric by Ivan Kust
Android Meetup Slovenija #3 - Testing with Robolectric by Ivan KustAndroid Meetup Slovenija #3 - Testing with Robolectric by Ivan Kust
Android Meetup Slovenija #3 - Testing with Robolectric by Ivan KustInfinum
 
Intro to React Native
Intro to React NativeIntro to React Native
Intro to React NativeForSharing
 
Testing on Android
Testing on AndroidTesting on Android
Testing on AndroidAri Lacenski
 
Mobile developer is Software developer
Mobile developer is Software developerMobile developer is Software developer
Mobile developer is Software developerEugen Martynov
 

Similar to Robolectric Adventure (20)

Robotium framework & Jenkins CI tools - TdT@Cluj #19
Robotium framework & Jenkins CI tools - TdT@Cluj #19Robotium framework & Jenkins CI tools - TdT@Cluj #19
Robotium framework & Jenkins CI tools - TdT@Cluj #19
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentation
 
Guide to the jungle of testing frameworks
Guide to the jungle of testing frameworksGuide to the jungle of testing frameworks
Guide to the jungle of testing frameworks
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 
Mockito a simple, intuitive mocking framework
Mockito   a simple, intuitive mocking frameworkMockito   a simple, intuitive mocking framework
Mockito a simple, intuitive mocking framework
 
Building XWiki
Building XWikiBuilding XWiki
Building XWiki
 
Robolectric v2
Robolectric v2Robolectric v2
Robolectric v2
 
Introduction to AndroidMock
Introduction to AndroidMockIntroduction to AndroidMock
Introduction to AndroidMock
 
Building Top-Notch Androids SDKs
Building Top-Notch Androids SDKsBuilding Top-Notch Androids SDKs
Building Top-Notch Androids SDKs
 
Mock your way with Mockito
Mock your way with MockitoMock your way with Mockito
Mock your way with Mockito
 
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)
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi Applications
 
Mobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileMobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve Mobile
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
Chegg - iOS @ Scale
Chegg - iOS @ ScaleChegg - iOS @ Scale
Chegg - iOS @ Scale
 
Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​
 
Android Meetup Slovenija #3 - Testing with Robolectric by Ivan Kust
Android Meetup Slovenija #3 - Testing with Robolectric by Ivan KustAndroid Meetup Slovenija #3 - Testing with Robolectric by Ivan Kust
Android Meetup Slovenija #3 - Testing with Robolectric by Ivan Kust
 
Intro to React Native
Intro to React NativeIntro to React Native
Intro to React Native
 
Testing on Android
Testing on AndroidTesting on Android
Testing on Android
 
Mobile developer is Software developer
Mobile developer is Software developerMobile developer is Software developer
Mobile developer is Software developer
 

More from Eugen Martynov

More from Eugen Martynov (8)

Kotlin Script
Kotlin ScriptKotlin Script
Kotlin Script
 
My path to freelance
My path to freelanceMy path to freelance
My path to freelance
 
Gradle Again
Gradle AgainGradle Again
Gradle Again
 
Android CD
Android CDAndroid CD
Android CD
 
Lokalise
LokaliseLokalise
Lokalise
 
DI with Dagger2
DI with Dagger2DI with Dagger2
DI with Dagger2
 
Flow
FlowFlow
Flow
 
XP Days UA Pecha kucha
XP Days UA Pecha kuchaXP Days UA Pecha kucha
XP Days UA Pecha kucha
 

Robolectric Adventure

  • 2. eBuddy • 2009 Chat (IM) • 2011 XMS • 2012 We started with Robolectric ANDROID PRODUCTS HISTORY
  • 4. Relationships • Java • Maven • Android • Unit tests
  • 5. First Android JUnit Test import 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" ); } }
  • 7. Android Testing Options • No tests • POJO • Instrumental tests • Android sources • Mock Android • Robolectric!
  • 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
  • 10. Key Points from Demo #1 • Correct path to SDK in the local.properties • JUnit dependency before Android (IntelliJ IDEA) • @RunWith( RobolectricTestRunner.class)
  • 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. Robolectric Drawbacks • Sometimes magic • PowerMock integration • Time of run for the first test
  • 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)
  • 15. RoboGuice 2.0 public 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() ) ); } }
  • 17. Key Points from Demo #2 • InjectingTestRunner • Own AbstractModule implementation • Run injections before every test method
  • 18. Android Real Jar (Robolectric 2.0) • http://robolectric.blogspot.nl /2011/08/using-robolectric- with-real-android.html • Robolectric 2.0 alpha
  • 19. Robolectric or not Robolectric • Not a question for me • Follow industry