Support slides for the test automation workshop realized at the iMasters Android DevConference 2015 at São Paulo. The workshop focus was around Unit Tests with JUnit, UI Tests with Espresso and UIAutomator and Testing your app in the cloud with Testdroid.
Right Money Management App For Your Financial Goals
Android Test Automation Workshop
1. Íntel Software and Services Group
Android:testautomationworkshopEduardo Carrara
Developer Evangelist – Intel Developers Relations Division
2. Intel Software and Services Group
#AndroidOnIntel
2
+EduardoCarraraDeAraujo
https://www.facebook.com/ducarrara
@DuCarrara
br.linkedin.com/in/eduardocarrara/
ecarrara-araujo
3. 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.
4. 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
5. 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
7. 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
8. Intel Software and Services Group 8
#1 – Creating your first Unit Test
Create these directories.
12. 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);
}
}
13. Intel Software and Services Group 13
#1 – Creating your first Unit Test
$ ./gradlew testor
14. Intel Software and Services Group 14
#1 – Creating your first Unit Test
or
appbuildreportstestsdebugindex.html
19. 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
20. Intel Software and Services Group 20
#2 Testing the ui with espresso
or $ ./gradlew connectedCheck
21. Intel Software and Services Group 21
#2 Testing the ui with espresso
or
appbuildreportsandroidTestsconnectedindex.html
24. Intel Software and Services Group 24
#3 Cross app Testing with UI Automator
25. Intel Software and Services Group 25
#3 Cross app Testing with UI Automator
26. Intel Software and Services Group 26
#3 Cross app Testing with UI Automator
Androidsdk/tools/uiautomatorviewer
27. 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
28. Intel Software and Services Group 28
#3 Cross app Testing with UI Automator
or $ ./gradlew connectedCheck
35. 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
36. Intel Software and Services Group 36
Intel Developer Zone
https://software.intel.com/en-us/android/app-testing
37. Intel Software and Services Group
Thanks!
37
+EduardoCarraraDeAraujo
https://www.facebook.com/ducarrara
@DuCarrara
br.linkedin.com/in/eduardocarrara/
ecarrara-araujo/vilibra