Android Testing: An Overview

3,084 views

Published on

A brief overview of android testing from SmartLogic's Eric Oestrich.

Published in: Technology
0 Comments
13 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,084
On SlideShare
0
From Embeds
0
Number of Embeds
31
Actions
Shares
0
Downloads
55
Comments
0
Likes
13
Embeds 0
No embeds

No notes for slide

Android Testing: An Overview

  1. 1. An Overview of Android Testing Eric Oestrich BohConf 7/19/2013
  2. 2. Eric Oestrich http://www.smartlogic.io https://twitter.com/ericoestrich https://github.com/oestrich SmartLogic
  3. 3. You can test Android?
  4. 4. Regular Android testing leaves a lot to be desired
  5. 5. Robolectric http://robolectric.org/
  6. 6. Run tests on your development machine
  7. 7. JUnit 4
  8. 8. Requires Maven
  9. 9. IntelliJ Supports maven projects
  10. 10. Eclipse Should just use IntelliJ
  11. 11. Android Studio Uses gradle, not much support for this yet
  12. 12. Downsides
  13. 13. Content Providers are still hard to test
  14. 14. Still somewhat new Not every area is able to be tested nicely
  15. 15. Lack of Documentation
  16. 16. Extra Libraries You Should Consider
  17. 17. Hamcrest http://hamcrest.org/JavaHamcrest/
  18. 18. Hamcrest ● Nicer assertions than regular JUnit
  19. 19. Hamcrest assertThat(item.getId(), equalTo(itemId));
  20. 20. FEST Android https://github.com/square/fest-android
  21. 21. FEST Android ● Fluent assertions make test read nicely ● FEST additions specific to Android
  22. 22. FEST Android assertThat(view.getVisibility(), equalTo(View.GONE)); vs assertThat(view).isGone();
  23. 23. Awaitility https://code.google.com/p/awaitility/
  24. 24. Awaitility ● Handles testing asynchronous code nicely ● Set timeouts
  25. 25. Awaitility public void testActivityTitle() { await().atMost(TIMEOUT_SECONDS, TimeUnit.SECONDS).until( activityTitle(), equalTo("Notification")); Spoon.screenshot(getActivity(), "activity_title"); }
  26. 26. Awaitility protected Callable<String> activityTitle() { return new Callable<String>() { @Override public String call() throws Exception { return mActivity.getTitle().toString(); } }; }
  27. 27. Spoon https://github.com/square/spoon
  28. 28. Spoon ● Take screenshots of app during test ● Compiles to animated gif ● Instrumentation tests
  29. 29. Spoon public void testActivity() { Spoon.screenshot(getActivity(), "activity"); }
  30. 30. Spoon http://square.github.io/spoon/sample/index.html
  31. 31. Continuous Integration
  32. 32. Jenkins Shell Script export ANDROID_HOME=/var/lib/jenkins/tools/android-sdk mvn clean test --batch-mode
  33. 33. Javadocs
  34. 34. JUnit Results
  35. 35. Android Emulator Plugin https://wiki.jenkins-ci. org/display/JENKINS/Android+Emulator+Plu gin
  36. 36. Resources ● http://corner.squareup.com/2013/05/robolectric-two-point-oh.html ● http://blog.bignerdranch.com/2583-testing-the-android-way/
  37. 37. Questions? http://www.smartlogic.io http://www.twitter.com/smartlogic http://www.github.com/smartlogic   http://www.facebook.com/smartlogic

×