Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Manifest Instrumentation

I have a android test project setup to test my android project. In the android test project's manifest, I have an entry for instrumentation. It looks like:

<instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="com.company.android" />

I'm curious what the point of this entry is, and particuarly what the purpose of android:targetPackage="com.company.android" is for. I ask, because I refactored the old project and put classes into different packages, so I'm curious on what I need to update this value to... is it suppose to point the the package where the class that extends android.app.Application is at?

like image 344
James Oravec Avatar asked Apr 16 '13 22:04

James Oravec


People also ask

What does Android manifest contain?

The AndroidManifest. xml file contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc.

What is an Android manifest and what is it for?

The Android manifest file helps to declare the permissions that an app must have to access data from other apps. The Android manifest file also specifies the app's package name that helps the Android SDK while building the app.

In which file would you list instrumentation classes?

For your New Relic-monitored Java application, one custom instrumentation method is to use an XML file that lists the methods and classes you want to instrument.

What are the elements in Android manifest XML file?

Structure of a Manifest file in Android is: The name of the application's package, it is generally the code's namespace. This information is used to determine the location of the code while building the project. Another component is the one, that includes all the activities, services, receivers, and content providers.


2 Answers

It tells the build system where to access the actual project you are going to test.

This is necessary because you need access to all your Activities and classes without having extra copies around.

Info about it is scattered around in: http://developer.android.com/tools/testing/testing_android.html

like image 175
Shellum Avatar answered Nov 27 '22 13:11

Shellum


InstrumentationTestRunner is something you use to write Android unit tests.

From the documentation:

Typical Usage

Write TestCases that perform unit, functional, or performance tests against the classes in your package. 
Typically these are subclassed from:

ActivityInstrumentationTestCase2
ActivityUnitTestCase
AndroidTestCase
ApplicationTestCase
InstrumentationTestCase
ProviderTestCase
ServiceTestCase
SingleLaunchActivityTestCase

In an appropriate AndroidManifest.xml, define the this instrumentation with the appropriate android:targetPackage set.
Run the instrumentation using "adb shell am instrument -w", with no optional arguments, to run all tests (except performance tests).
Run the instrumentation using "adb shell am instrument -w", with the argument '-e func true' to run all functional tests. These are tests that derive from InstrumentationTestCase.
Run the instrumentation using "adb shell am instrument -w", with the argument '-e unit true' to run all unit tests. These are tests that do notderive from InstrumentationTestCase (and are not performance tests).
Run the instrumentation using "adb shell am instrument -w", with the argument '-e class' set to run an individual TestCase.
like image 37
Codeman Avatar answered Nov 27 '22 13:11

Codeman