TESTING ANDROID
                                     Marc Chung
                                      OpenRain
           ...
Agenda


                   Introduce Android testing concepts

                   Unit and mock testing + Demos

        ...
Unit testing in Java

                   JUnit is the most popular framework

                   Most projects, frameworks...
Unit testing demo


                   Twitter Demo

                          Uses JUnit

                          Login...
public void testStatusUpdate() {
                   try {
                     IMyTwitter twitter = new MyTwitter("superte...
Mock Objects in Java

                   A Mock is “fake” object which mimics real objects for the
                   purp...
Mock testing demo


                   Twitter Demo

                          Uses EasyMock

                          Av...
public void testStatusUpdate() {	
                             String updateStatus = "Hello Phoenix Android";

           ...
Android Testing


                   Testing Android requires JUnit

                   Write tests to run and test parts ...
Setting up your project
                      Using the command line tool will create a tests/ directory
                 ...
Running Android tests


                   Two ways to run your tests

                          Command line runner

    ...
AndroidTestCase


                   unit testing

                   faster and easier to boot strap

                   ...
ActivityInstrumentationTestCase


                   functional unit testing

                   access to a real live Act...
Instrumentation Demo



                   Functional tests

                          Test drives the Activity




Friday...
Other Android tests
                   ServiceTestCase

                          For testing services

                  ...
More Android testing


                   Testing APIs
                          http://developer.android.com/reference/an...
Tips


                   Isolate and test non-Android code separately.

                   Functional tests use live obje...
Future topics


                   Code coverage tools

                   Continuous integration tools

                 ...
Thank you


                   Join Phoenix Android Mailing list

                          http://phoenixandroid.com

   ...
Upcoming SlideShare
Loading in...5
×

Testing Android

9,132

Published on

Learn about unit testing Android applications

Published in: Technology, Business
1 Comment
6 Likes
Statistics
Notes
No Downloads
Views
Total Views
9,132
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
253
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

Transcript of "Testing Android"

  1. 1. TESTING ANDROID Marc Chung OpenRain marc.chung@openrain.com Friday, August 28, 2009 1
  2. 2. Agenda Introduce Android testing concepts Unit and mock testing + Demos Android testing overview + Demos Q&A Friday, August 28, 2009 2
  3. 3. Unit testing in Java JUnit is the most popular framework Most projects, frameworks, IDEs will ship with support Out of the box, Eclipse IDE has good JUnit support There are many frameworks http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#Java Friday, August 28, 2009 3
  4. 4. Unit testing demo Twitter Demo Uses JUnit Login/password Update status Friday, August 28, 2009 4
  5. 5. public void testStatusUpdate() { try { IMyTwitter twitter = new MyTwitter("supertesting", "s3!kretep@s5"); TwitterClient client = new TwitterClient(twitter); String update = "Hello Phoenix Android"; client.post(update); Assert.assertEquals(update, client.getLatestPost()); } catch (TwitterException te) { Assert.fail("Shouldn't see this because the credentials are correct"); } } Friday, August 28, 2009 5
  6. 6. Mock Objects in Java A Mock is “fake” object which mimics real objects for the purpose of testing Mimics real objects for testing Such as a web service request Mocking is a style of testing http://martinfowler.com/articles/mocksArentStubs.html Friday, August 28, 2009 6
  7. 7. Mock testing demo Twitter Demo Uses EasyMock Avoid issuing live requests Friday, August 28, 2009 7
  8. 8. public void testStatusUpdate() { String updateStatus = "Hello Phoenix Android"; IMyTwitter mockedTwitter = EasyMock.createMock(IMyTwitter.class); expect(mockedTwitter.getStatus()).andReturn(null); expect(mockedTwitter.updateStatus(updateStatus)).andReturn(null); replay(mockedTwitter); TwitterClient client = new TwitterClient(mockedTwitter); client.post(updateStatus); Assert.assertEquals(updateStatus, client.getLatestPost()); verify(mockedTwitter); } Friday, August 28, 2009 8
  9. 9. Android Testing Testing Android requires JUnit Write tests to run and test parts of your application InstrumentationTestRunner runs your test as an application Executes code on emulator Friday, August 28, 2009 9
  10. 10. Setting up your project Using the command line tool will create a tests/ directory inside the project. android create project -t 3 -n hello_world -p hello_world -a HelloWorld -k com.openrain.hello_world Use Eclipse manually. Doesn’t create a tests/ directory Manually create two projects. Friday, August 28, 2009 10
  11. 11. Running Android tests Two ways to run your tests Command line runner Eclipse runner Friday, August 28, 2009 11
  12. 12. AndroidTestCase unit testing faster and easier to boot strap only have access to a Context useful for asserting layout, position, and components Friday, August 28, 2009 12
  13. 13. ActivityInstrumentationTestCase functional unit testing access to a real live Activity instance may simulate key events slower Friday, August 28, 2009 13
  14. 14. Instrumentation Demo Functional tests Test drives the Activity Friday, August 28, 2009 14
  15. 15. Other Android tests ServiceTestCase For testing services ActivityUnitTestCase and ActivityTestCase For testing an Activity in isolation ApplicationTestCase Full integration testing Friday, August 28, 2009 15
  16. 16. More Android testing Testing APIs http://developer.android.com/reference/android/test/package-summary.html android.test android.test.mock Friday, August 28, 2009 16
  17. 17. Tips Isolate and test non-Android code separately. Functional tests use live objects. Slow, but reliable. Javadoc is your friend Friday, August 28, 2009 17
  18. 18. Future topics Code coverage tools Continuous integration tools Performance testing Friday, August 28, 2009 18
  19. 19. Thank you Join Phoenix Android Mailing list http://phoenixandroid.com Follow me on Twitter: @heisenthought Friday, August 28, 2009 19
  1. A particular slide catching your eye?

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

×