SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
Unit Testing in
            Android

Li-Wei Cheng
Outline
•    Android Testing Framework

•    Test Projects

•    The Testing API

•    Running Tests

•    Seeing Test Results
Android Testing Framework (1)
•   An integral part of the development
    environment.

•   Provides architecture and powerful tools help
    you to test your app at every level from unit to
    framework.
Android Testing Framework (2)
•   Key features for the testing framework (1)
    o   Android Test Suites are based on JUnit.
           Use plain JUnit to test a class doesn't call the Android API.
           Use Android's JUnit extensions to test Android components.

    o   Android JUnit extensions provide component-specific
        test classes.
           Helper methods for creating mock objects.
           Helper methods for controlling the lifecycle of a component.

    o   Test suites are contained in test packages that are
        similar to a main application packages.
           You don't to learn a new set of tools or techniques for
           designing and building tests.
Android Testing Framework (3)
•   Key features for the testing framework (2)
    o   The SDK tools for building and tests are available in
        Eclipse with ADT, and also in command-line form for
        use with other IDES.
           These tools get information from the project of the application
           under test and use this information to automatically create the
           build files, manifest file and the directory structure for the test
           package.

    o   The SDK also provides
           monkeyrunner, a API testing devices with Python programs.
           UI/Application Exerciser Monkey, a command-line tool for
           stress-testing UIs by sending pseudo-random events to a
           device.
Android Testing Framework (4)
•   Summarize Testing Framework
Test Projects (1)
•   Test, like Android applications, are organized
    into projects.




                   test project usually bundles with tested project
Test Projects (2)
•   Two ways to create your test project
    o   Using ADT
           An eclipse plugin will generate files automatically.


    o   Using command-line tools
           It will create Ant build files you need automatically.
Test Projects (3)
•   Use Android tools to create test project having
    the following benefits:
    o Set up your test project to use the
      InstrumentationTestRunner as the test case runner.

    o Create appropriate package name for the test
      project.

    o Automatically create the proper build files.
          Manifest files and directory structure for the test project.
          Helps you to build the test project without having to modify
          build files and sets up the linkage between test package
          and the application under test.
The Testing API (1)
•   Provided by JUnit.
    o   TestCase Class
           To do unit testing on a class that doesn't call Android APIs.
           Offers setup, and teardown methods.
    o   JUnit Assertion Class
           Compare values you expect from a test to the actual results and
           throw an exception if the comparison fails.
           Display the test results.

•   Provided by Android.
    o   AndroidTestCase Class
           A subclass of TestCase in JUnit.
           Offers Android-specific setup, teardown, and helper methods.
    o   Android Assertion Class
           A subclass of Junit Assertion class.
The Testing API (2)
•   Provided by Android.
    o   Instrumentation
           A set of control methods or "hooks" in the Android system.
          These hooks control an Android component independently of
          its normal lifecycle.
           Use instrumentation to invoke the activity's lifecycle callback
           directly.

    o   InstrumentationTestCase
           A subclass of JUnit's TestCase Class.
           The class can access the instance of instrumentation directly.
The Testing API (3)
•   Provided by Android.
    o   ApplicationTestCase
           It's useful to verify that the <application> elements in the
           manifest file is correctly set up.

    o   Component-specific test cases
            Activity Testing
            Service Testing
            Content Provider Testing
        Android doesn't provide a separate test case for
        BroadcastReceiver. Instead, test a BroadcastReceiver by testing
        the component that sends it intent object, to verify that the
        BroadcastReceiver responds correctly.
The Testing API (4)
•   Provided by Android.
    o Mock object classes
    o Context for testing
Example (1)
    test target




    test apk
Example (2)
Example (3)

Weitere ähnliche Inhalte

Was ist angesagt?

Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage Introduction
Alex Su
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
Joe Wilson
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Jacinto Limjap
 
N Unit Presentation
N Unit PresentationN Unit Presentation
N Unit Presentation
priya_trivedi
 
Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
Dror Helper
 

Was ist angesagt? (20)

Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
 
Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage Introduction
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
NUnit Features Presentation
NUnit Features PresentationNUnit Features Presentation
NUnit Features Presentation
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Intro To Unit and integration Testing
Intro To Unit and integration TestingIntro To Unit and integration Testing
Intro To Unit and integration Testing
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
 
N Unit Presentation
N Unit PresentationN Unit Presentation
N Unit Presentation
 
Testing In Java
Testing In JavaTesting In Java
Testing In Java
 
Junit
JunitJunit
Junit
 
UNIT TESTING
UNIT TESTINGUNIT TESTING
UNIT TESTING
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
 
Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
 
Unit test
Unit testUnit test
Unit test
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeJUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit testing with NUnit
Unit testing with NUnitUnit testing with NUnit
Unit testing with NUnit
 

Andere mochten auch

Testing Android apps with Robotium
Testing Android apps with RobotiumTesting Android apps with Robotium
Testing Android apps with Robotium
Stephen Gilmore
 
Performance Testing on Android
Performance Testing on AndroidPerformance Testing on Android
Performance Testing on Android
Akshay Dashrath
 

Andere mochten auch (20)

Tdd
TddTdd
Tdd
 
Testing Android apps with Robotium
Testing Android apps with RobotiumTesting Android apps with Robotium
Testing Android apps with Robotium
 
Android Mobile Application Testing: Specific Functional, Performance, Device ...
Android Mobile Application Testing: Specific Functional, Performance, Device ...Android Mobile Application Testing: Specific Functional, Performance, Device ...
Android Mobile Application Testing: Specific Functional, Performance, Device ...
 
Performance Testing on Android
Performance Testing on AndroidPerformance Testing on Android
Performance Testing on Android
 
Android performance
Android performanceAndroid performance
Android performance
 
Android Performance and Monitoring - Meetup 3 25-14
Android Performance and Monitoring - Meetup 3 25-14Android Performance and Monitoring - Meetup 3 25-14
Android Performance and Monitoring - Meetup 3 25-14
 
Testing Android Security
Testing Android SecurityTesting Android Security
Testing Android Security
 
How to Reliably Measure and Optimize Graphics Performance of Your Android Games
How to Reliably Measure and Optimize Graphics Performance of Your Android GamesHow to Reliably Measure and Optimize Graphics Performance of Your Android Games
How to Reliably Measure and Optimize Graphics Performance of Your Android Games
 
Testing on Android
Testing on AndroidTesting on Android
Testing on Android
 
Testing for Android: When, Where, and How to Successfully Use Test Automation
Testing for Android: When, Where, and How to Successfully Use Test AutomationTesting for Android: When, Where, and How to Successfully Use Test Automation
Testing for Android: When, Where, and How to Successfully Use Test Automation
 
Introduction to android testing - oscon 2012
Introduction to android testing - oscon 2012Introduction to android testing - oscon 2012
Introduction to android testing - oscon 2012
 
Android Performance Tips & Tricks
Android Performance Tips & TricksAndroid Performance Tips & Tricks
Android Performance Tips & Tricks
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 
Android Testing: An Overview
Android Testing: An OverviewAndroid Testing: An Overview
Android Testing: An Overview
 
Testing Android Application, Droidcon Torino
Testing Android Application, Droidcon TorinoTesting Android Application, Droidcon Torino
Testing Android Application, Droidcon Torino
 
Testing Android applications with Maveryx
Testing Android applications with MaveryxTesting Android applications with Maveryx
Testing Android applications with Maveryx
 
Inside Android Testing
Inside Android TestingInside Android Testing
Inside Android Testing
 
Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016
Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016
Unit Testing on Android: why and how? DevFest Romania, Bucharest 2016
 
Android Building, Testing and reversing
Android Building, Testing and reversingAndroid Building, Testing and reversing
Android Building, Testing and reversing
 
Testing Android
Testing AndroidTesting Android
Testing Android
 

Ähnlich wie Unit testing in android

Android studio&Gradle&Autotest
Android studio&Gradle&AutotestAndroid studio&Gradle&Autotest
Android studio&Gradle&Autotest
毅 方
 
Unit testing
Unit testingUnit testing
Unit testing
medsherb
 
Unit testing_pps
Unit testing_ppsUnit testing_pps
Unit testing_pps
Gaurav Keshre
 

Ähnlich wie Unit testing in android (20)

Android testing
Android testingAndroid testing
Android testing
 
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
SE2011_10.ppt
SE2011_10.pptSE2011_10.ppt
SE2011_10.ppt
 
Innovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesInnovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best Practices
 
Unit Testing to Support Reusable for Component-Based Software Engineering
Unit Testing to Support Reusable for Component-Based Software EngineeringUnit Testing to Support Reusable for Component-Based Software Engineering
Unit Testing to Support Reusable for Component-Based Software Engineering
 
Ian Sommerville, Software Engineering, 9th EditionCh 8
Ian Sommerville,  Software Engineering, 9th EditionCh 8Ian Sommerville,  Software Engineering, 9th EditionCh 8
Ian Sommerville, Software Engineering, 9th EditionCh 8
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
 
Open Source Software Testing Tools
Open Source Software Testing ToolsOpen Source Software Testing Tools
Open Source Software Testing Tools
 
Android studio&Gradle&Autotest
Android studio&Gradle&AutotestAndroid studio&Gradle&Autotest
Android studio&Gradle&Autotest
 
Unit testing
Unit testingUnit testing
Unit testing
 
SDET UNIT 4.pptx
SDET UNIT 4.pptxSDET UNIT 4.pptx
SDET UNIT 4.pptx
 
Unit testing_pps
Unit testing_ppsUnit testing_pps
Unit testing_pps
 
Test Complete
Test CompleteTest Complete
Test Complete
 
Unit Testing in Angular
Unit Testing in AngularUnit Testing in Angular
Unit Testing in Angular
 
A guide to Android automated testing
A guide to Android automated testingA guide to Android automated testing
A guide to Android automated testing
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
QTP 10.0_Kalyan Chakravarthy.ppt
QTP 10.0_Kalyan Chakravarthy.pptQTP 10.0_Kalyan Chakravarthy.ppt
QTP 10.0_Kalyan Chakravarthy.ppt
 

Mehr von Li-Wei Cheng (6)

Introduction to AndroidMock
Introduction to AndroidMockIntroduction to AndroidMock
Introduction to AndroidMock
 
Make Your SW Component Testable
Make Your SW Component TestableMake Your SW Component Testable
Make Your SW Component Testable
 
Test doubles
Test doublesTest doubles
Test doubles
 
JUnit
JUnitJUnit
JUnit
 
OO design principle
OO design principleOO design principle
OO design principle
 
UML knowledge
UML knowledgeUML knowledge
UML knowledge
 

KĂźrzlich hochgeladen

KĂźrzlich hochgeladen (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Unit testing in android

  • 1. Unit Testing in Android Li-Wei Cheng
  • 2. Outline • Android Testing Framework • Test Projects • The Testing API • Running Tests • Seeing Test Results
  • 3. Android Testing Framework (1) • An integral part of the development environment. • Provides architecture and powerful tools help you to test your app at every level from unit to framework.
  • 4. Android Testing Framework (2) • Key features for the testing framework (1) o Android Test Suites are based on JUnit. Use plain JUnit to test a class doesn't call the Android API. Use Android's JUnit extensions to test Android components. o Android JUnit extensions provide component-specific test classes. Helper methods for creating mock objects. Helper methods for controlling the lifecycle of a component. o Test suites are contained in test packages that are similar to a main application packages. You don't to learn a new set of tools or techniques for designing and building tests.
  • 5. Android Testing Framework (3) • Key features for the testing framework (2) o The SDK tools for building and tests are available in Eclipse with ADT, and also in command-line form for use with other IDES. These tools get information from the project of the application under test and use this information to automatically create the build files, manifest file and the directory structure for the test package. o The SDK also provides monkeyrunner, a API testing devices with Python programs. UI/Application Exerciser Monkey, a command-line tool for stress-testing UIs by sending pseudo-random events to a device.
  • 6. Android Testing Framework (4) • Summarize Testing Framework
  • 7. Test Projects (1) • Test, like Android applications, are organized into projects. test project usually bundles with tested project
  • 8. Test Projects (2) • Two ways to create your test project o Using ADT An eclipse plugin will generate files automatically. o Using command-line tools It will create Ant build files you need automatically.
  • 9. Test Projects (3) • Use Android tools to create test project having the following benefits: o Set up your test project to use the InstrumentationTestRunner as the test case runner. o Create appropriate package name for the test project. o Automatically create the proper build files. Manifest files and directory structure for the test project. Helps you to build the test project without having to modify build files and sets up the linkage between test package and the application under test.
  • 10. The Testing API (1) • Provided by JUnit. o TestCase Class To do unit testing on a class that doesn't call Android APIs. Offers setup, and teardown methods. o JUnit Assertion Class Compare values you expect from a test to the actual results and throw an exception if the comparison fails. Display the test results. • Provided by Android. o AndroidTestCase Class A subclass of TestCase in JUnit. Offers Android-specific setup, teardown, and helper methods. o Android Assertion Class A subclass of Junit Assertion class.
  • 11. The Testing API (2) • Provided by Android. o Instrumentation A set of control methods or "hooks" in the Android system. These hooks control an Android component independently of its normal lifecycle. Use instrumentation to invoke the activity's lifecycle callback directly. o InstrumentationTestCase A subclass of JUnit's TestCase Class. The class can access the instance of instrumentation directly.
  • 12. The Testing API (3) • Provided by Android. o ApplicationTestCase It's useful to verify that the <application> elements in the manifest file is correctly set up. o Component-specific test cases Activity Testing Service Testing Content Provider Testing Android doesn't provide a separate test case for BroadcastReceiver. Instead, test a BroadcastReceiver by testing the component that sends it intent object, to verify that the BroadcastReceiver responds correctly.
  • 13. The Testing API (4) • Provided by Android. o Mock object classes o Context for testing
  • 14. Example (1) test target test apk