Íntel Software and Services Group Android:testautomationworkshopEduardo Carrara Developer Evangelist – Intel Developers Relations Division
Intel Software and Services Group #AndroidOnIntel 2 +EduardoCarraraDeAraujo https://www.facebook.com/ducarrara @DuCarrara br.linkedin.com/in/eduardocarrara/ ecarrara-araujo
Intel Software and Services Group 3 Objective Practice the usage of test automation tools available in the Android Framework through the following activities: • Prepare the test environment for development and execution. • Development of unit tests that run on the local JVM. • Development of UI Tests with Espresso. • Development of Cross Apps Tests with UI Automator. • Running tests in the cloud with TestDroid.
Intel Software and Services Group 4 Requirements • Android Studio 1.3+ • Test Device with Android 4.0+ • SDK Version 23 • Build Tools 23.0.0 • AppCompat-v7 23.3.0
Intel Software and Services Group 5 Base App - BeerWith • Simple demo app to help you keep track of what have you been drinking and with who. • https://github.com/ecarrara-araujo/beer-with • If you want to follow the workshop just clone it and work on branch master. • Check the branch ahead for the implementations: • Imasters-android-devconf-tests-workshop
Intel Software and Services Group #1–CreatingyourfirstUnitTest 6
Intel Software and Services Group 7 #1 – Creating your first Unit Test testCompile 'junit:junit:4.12' • Add the Junit dependency to the app/build.gradle
Intel Software and Services Group 8 #1 – Creating your first Unit Test Create these directories.
Intel Software and Services Group 9 #1 – Creating your first Unit Test
Intel Software and Services Group 10 #1 – Creating your first Unit Test
Intel Software and Services Group 11 #1 – Creating your first Unit Test
Intel Software and Services Group 12 #1 – Creating your first Unit Test public class UtilityTest { @Test public void testGetDateFormattedTime() throws Exception { String expectedDateFormat = "yyyy, MMMM dd"; Calendar calendar = Calendar.getInstance(); calendar.set(2015, 4 - 1, 3); //20150403 String expectedResult = (new SimpleDateFormat(expectedDateFormat)).format(calendar.getTime()); String result = Utility.getDateFormattedTime(calendar, expectedDateFormat); assertEquals("Date was not correctly formatted.", expectedResult, result); // testing a second format to be sure expectedDateFormat = "dd MM yyyy"; expectedResult = (new SimpleDateFormat(expectedDateFormat)).format(calendar.getTime()); result = Utility.getDateFormattedTime(calendar, expectedDateFormat); assertEquals("Date was not correctly formatted.", expectedResult, result); } }
Intel Software and Services Group 13 #1 – Creating your first Unit Test $ ./gradlew testor
Intel Software and Services Group 14 #1 – Creating your first Unit Test or appbuildreportstestsdebugindex.html
Intel Software and Services Group #2Testingtheuiwithespresso 15
Intel Software and Services Group 16 #2 Testing the ui with espresso • App/build.gradle defaultConfig { testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' } dependencies { androidTestCompile 'com.android.support.test:runner:0.3' androidTestCompile 'com.android.support.test:rules:0.3' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' } • ./build.gradle allprojects { configurations.all { resolutionStrategy.force 'com.android.support:support-annotations:23.0.0' } }
Intel Software and Services Group 17 #2 Testing the ui with espresso
Intel Software and Services Group 18 #2 Testing the ui with espresso
Intel Software and Services Group 19 #2 Testing the ui with espresso Here comes a whole lot of code… Check the file: BeerWithappsrcandroidTestjavabrengecarrarabeerwit hBeerWithMainActivityInstrumentationTest.java
Intel Software and Services Group 20 #2 Testing the ui with espresso or $ ./gradlew connectedCheck
Intel Software and Services Group 21 #2 Testing the ui with espresso or appbuildreportsandroidTestsconnectedindex.html
Intel Software and Services Group #3CROssappTestingwithUIAutomator 22
Intel Software and Services Group 23 #3 Cross app Testing with UI Automator • App/build.gradle defaultConfig { testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' } • ./build.gradle allprojects { configurations.all { resolutionStrategy.force 'com.android.support:support-annotations:23.0.0' } } dependecies { androidTestCompile 'com.android.support.test:runner:0.3' androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1' androidTestCompile 'org.hamcrest:hamcrest-integration:1.3' }
Intel Software and Services Group 24 #3 Cross app Testing with UI Automator
Intel Software and Services Group 25 #3 Cross app Testing with UI Automator
Intel Software and Services Group 26 #3 Cross app Testing with UI Automator Androidsdk/tools/uiautomatorviewer
Intel Software and Services Group 27 #3 Cross app Testing with UI Automator Here comes a whole lot of code… Check the file: BeerWithappsrcandroidTestjavabrengecarrarabeerwit hAddingBeerWithCompleteTestFlow.java
Intel Software and Services Group 28 #3 Cross app Testing with UI Automator or $ ./gradlew connectedCheck
Intel Software and Services Group 29 or
Intel Software and Services Group 30
Intel Software and Services Group 31
Intel Software and Services Group 32
Intel Software and Services Group 33
Intel Software and Services Group 34
Intel Information Technology What is next? 35 • Follow the guide and automate your tests! • How to integrate continous integration and delivery with Android? • Code Coverage • Mocking
Intel Software and Services Group 36 Intel Developer Zone https://software.intel.com/en-us/android/app-testing
Intel Software and Services Group Thanks! 37 +EduardoCarraraDeAraujo https://www.facebook.com/ducarrara @DuCarrara br.linkedin.com/in/eduardocarrara/ ecarrara-araujo/vilibra
Intel Software and Services Group 38 References • Android Testing: https://developer.android.com/tools/testing/testing_android.html • Android Unit Testing Support: http://tools.android.com/tech-docs/unit-testing-support • UI Testing: https://developer.android.com/training/testing/ui-testing/index.html • Android Testing Support Library: https://developer.android.com/tools/testing-support- library • Android Instrumentation: http://developer.android.com/tools/testing/testing_android.html#Instrumentation • Junit: http://junit.org • Testdroid: http://testdroid.com • Intel App Testing Page: https://software.intel.com/en-us/android/app-testing
Intel Software and Services Group 39 References • Codelab Android Studio Testing: https://io2015codelabs.appspot.com/codelabs/android- studio-testing#1 • Android Testing Blueprints: https://github.com/googlesamples/android-testing- templates/tree/master/AndroidTestingBlueprint • Testing on Android by Vincent Brison: http://vincentbrison.com/2015/08/05/testing-on- android-part1-a-practical-approach/ • Android Developers Unit Testing Training: https://developer.android.com/training/testing/unit-testing/index.html • Android Testing Samples: https://github.com/googlesamples/android-testing/ • G+ Community: https://plus.google.com/communities/10515313437206298596 • Stack Overflow: http://stackoverflow.com/questions/tagged/android-testing
Intel Software and Services Group 40 References • Espresso v2 Cheat Sheet - https://code.google.com/p/android-test- kit/wiki/EspressoV2CheatSheet
Placeholder Footer Copy / BU Logo or Name Goes Here

Android Test Automation Workshop

  • 1.
    Íntel Software andServices Group Android:testautomationworkshopEduardo Carrara Developer Evangelist – Intel Developers Relations Division
  • 2.
    Intel Software andServices Group #AndroidOnIntel 2 +EduardoCarraraDeAraujo https://www.facebook.com/ducarrara @DuCarrara br.linkedin.com/in/eduardocarrara/ ecarrara-araujo
  • 3.
    Intel Software andServices Group 3 Objective Practice the usage of test automation tools available in the Android Framework through the following activities: • Prepare the test environment for development and execution. • Development of unit tests that run on the local JVM. • Development of UI Tests with Espresso. • Development of Cross Apps Tests with UI Automator. • Running tests in the cloud with TestDroid.
  • 4.
    Intel Software andServices Group 4 Requirements • Android Studio 1.3+ • Test Device with Android 4.0+ • SDK Version 23 • Build Tools 23.0.0 • AppCompat-v7 23.3.0
  • 5.
    Intel Software andServices Group 5 Base App - BeerWith • Simple demo app to help you keep track of what have you been drinking and with who. • https://github.com/ecarrara-araujo/beer-with • If you want to follow the workshop just clone it and work on branch master. • Check the branch ahead for the implementations: • Imasters-android-devconf-tests-workshop
  • 6.
    Intel Software andServices Group #1–CreatingyourfirstUnitTest 6
  • 7.
    Intel Software andServices Group 7 #1 – Creating your first Unit Test testCompile 'junit:junit:4.12' • Add the Junit dependency to the app/build.gradle
  • 8.
    Intel Software andServices Group 8 #1 – Creating your first Unit Test Create these directories.
  • 9.
    Intel Software andServices Group 9 #1 – Creating your first Unit Test
  • 10.
    Intel Software andServices Group 10 #1 – Creating your first Unit Test
  • 11.
    Intel Software andServices Group 11 #1 – Creating your first Unit Test
  • 12.
    Intel Software andServices Group 12 #1 – Creating your first Unit Test public class UtilityTest { @Test public void testGetDateFormattedTime() throws Exception { String expectedDateFormat = "yyyy, MMMM dd"; Calendar calendar = Calendar.getInstance(); calendar.set(2015, 4 - 1, 3); //20150403 String expectedResult = (new SimpleDateFormat(expectedDateFormat)).format(calendar.getTime()); String result = Utility.getDateFormattedTime(calendar, expectedDateFormat); assertEquals("Date was not correctly formatted.", expectedResult, result); // testing a second format to be sure expectedDateFormat = "dd MM yyyy"; expectedResult = (new SimpleDateFormat(expectedDateFormat)).format(calendar.getTime()); result = Utility.getDateFormattedTime(calendar, expectedDateFormat); assertEquals("Date was not correctly formatted.", expectedResult, result); } }
  • 13.
    Intel Software andServices Group 13 #1 – Creating your first Unit Test $ ./gradlew testor
  • 14.
    Intel Software andServices Group 14 #1 – Creating your first Unit Test or appbuildreportstestsdebugindex.html
  • 15.
    Intel Software andServices Group #2Testingtheuiwithespresso 15
  • 16.
    Intel Software andServices Group 16 #2 Testing the ui with espresso • App/build.gradle defaultConfig { testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' } dependencies { androidTestCompile 'com.android.support.test:runner:0.3' androidTestCompile 'com.android.support.test:rules:0.3' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' } • ./build.gradle allprojects { configurations.all { resolutionStrategy.force 'com.android.support:support-annotations:23.0.0' } }
  • 17.
    Intel Software andServices Group 17 #2 Testing the ui with espresso
  • 18.
    Intel Software andServices Group 18 #2 Testing the ui with espresso
  • 19.
    Intel Software andServices Group 19 #2 Testing the ui with espresso Here comes a whole lot of code… Check the file: BeerWithappsrcandroidTestjavabrengecarrarabeerwit hBeerWithMainActivityInstrumentationTest.java
  • 20.
    Intel Software andServices Group 20 #2 Testing the ui with espresso or $ ./gradlew connectedCheck
  • 21.
    Intel Software andServices Group 21 #2 Testing the ui with espresso or appbuildreportsandroidTestsconnectedindex.html
  • 22.
    Intel Software andServices Group #3CROssappTestingwithUIAutomator 22
  • 23.
    Intel Software andServices Group 23 #3 Cross app Testing with UI Automator • App/build.gradle defaultConfig { testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' } • ./build.gradle allprojects { configurations.all { resolutionStrategy.force 'com.android.support:support-annotations:23.0.0' } } dependecies { androidTestCompile 'com.android.support.test:runner:0.3' androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1' androidTestCompile 'org.hamcrest:hamcrest-integration:1.3' }
  • 24.
    Intel Software andServices Group 24 #3 Cross app Testing with UI Automator
  • 25.
    Intel Software andServices Group 25 #3 Cross app Testing with UI Automator
  • 26.
    Intel Software andServices Group 26 #3 Cross app Testing with UI Automator Androidsdk/tools/uiautomatorviewer
  • 27.
    Intel Software andServices Group 27 #3 Cross app Testing with UI Automator Here comes a whole lot of code… Check the file: BeerWithappsrcandroidTestjavabrengecarrarabeerwit hAddingBeerWithCompleteTestFlow.java
  • 28.
    Intel Software andServices Group 28 #3 Cross app Testing with UI Automator or $ ./gradlew connectedCheck
  • 29.
    Intel Software andServices Group 29 or
  • 30.
    Intel Software andServices Group 30
  • 31.
    Intel Software andServices Group 31
  • 32.
    Intel Software andServices Group 32
  • 33.
    Intel Software andServices Group 33
  • 34.
    Intel Software andServices Group 34
  • 35.
    Intel Information Technology Whatis next? 35 • Follow the guide and automate your tests! • How to integrate continous integration and delivery with Android? • Code Coverage • Mocking
  • 36.
    Intel Software andServices Group 36 Intel Developer Zone https://software.intel.com/en-us/android/app-testing
  • 37.
    Intel Software andServices Group Thanks! 37 +EduardoCarraraDeAraujo https://www.facebook.com/ducarrara @DuCarrara br.linkedin.com/in/eduardocarrara/ ecarrara-araujo/vilibra
  • 38.
    Intel Software andServices Group 38 References • Android Testing: https://developer.android.com/tools/testing/testing_android.html • Android Unit Testing Support: http://tools.android.com/tech-docs/unit-testing-support • UI Testing: https://developer.android.com/training/testing/ui-testing/index.html • Android Testing Support Library: https://developer.android.com/tools/testing-support- library • Android Instrumentation: http://developer.android.com/tools/testing/testing_android.html#Instrumentation • Junit: http://junit.org • Testdroid: http://testdroid.com • Intel App Testing Page: https://software.intel.com/en-us/android/app-testing
  • 39.
    Intel Software andServices Group 39 References • Codelab Android Studio Testing: https://io2015codelabs.appspot.com/codelabs/android- studio-testing#1 • Android Testing Blueprints: https://github.com/googlesamples/android-testing- templates/tree/master/AndroidTestingBlueprint • Testing on Android by Vincent Brison: http://vincentbrison.com/2015/08/05/testing-on- android-part1-a-practical-approach/ • Android Developers Unit Testing Training: https://developer.android.com/training/testing/unit-testing/index.html • Android Testing Samples: https://github.com/googlesamples/android-testing/ • G+ Community: https://plus.google.com/communities/10515313437206298596 • Stack Overflow: http://stackoverflow.com/questions/tagged/android-testing
  • 40.
    Intel Software andServices Group 40 References • Espresso v2 Cheat Sheet - https://code.google.com/p/android-test- kit/wiki/EspressoV2CheatSheet
  • 41.
    Placeholder Footer Copy/ BU Logo or Name Goes Here