Table of Contents |
---|
Introduction
For Android Studio usage:
...
Code Block | ||
---|---|---|
| ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> |
...
IMPORTANT
...
===============================
Beginning in Android 6.0 (API level 23), some permissions are now considered *dangerous*.
The permissions *android.permission.READ_EXTERNAL_STORAGE* and *android.permission.WRITE_EXTERNAL_STORAGE* must be granted explicitly via ADB commands for the measures to work.
...
Code Block | ||
---|---|---|
| ||
adb shell pm grant com.example.myapp android.permission.READ_EXTERNAL_STORAGE adb shell pm grant com.example.myapp android.permission.WRITE_EXTERNAL_STORAGE |
...
...
Integration
...
Generic Android Integration
...
API
Code Block | ||
---|---|---|
| ||
setUpMeasure(Context context, String[] packageName, int[] lstPid, String Appname, String Version, String URL, String privateToken, int timeout, int interval, boolean online) |
...
Sends the number of the completed tests to the probe. Enables the number of tests identification and the calculation of standardized metrics.=====
Integration with your program
Usage example:
Code Block | ||
---|---|---|
| ||
package com.greenspector.sample.BasicExample; import android.content.Context; import android.test.InstrumentationTestCase; import android.support.test.InstrumentationRegistry; import com.greenspector.probe.android.interfaces.Api; public class GreenspectorBasicExample extends InstrumentationTestCase { // Package to measure private static final String BASIC_SAMPLE_PACKAGE = "com.android.chrome"; /** Probe configuration **/ private static final String APPLICATION = "TestApplication"; private static final String VERSION = "1.0.2"; private static final String URL = "https://my-instance.greenspector.com/api"; private static final String PRIVATETOKEN = "123456789AZERTY"; private static final int TIMEOUT = 180; private static final int INTERVAL = 200; private static final boolean ONLINE = true; private Api gsptpp; public void testBasicExample() { gsptpp = new Api(); gsptpp.setUpMeasure(getInstrumentation().getTargetContext(), new String[]{BASIC_SAMPLE_PACKAGE}, null, APPLICATION, VERSION, URL, PRIVATETOKEN, TIMEOUT, INTERVAL, ONLINE); gsptpp.startMeasure(); try { Thread.sleep(10000); } catch (InterruptedException e) { gsptpp.stopMeasure("test_Idle_Failed"); return; } gsptpp.stopMeasure("test_Idle"); } } |
...
Usage with Greenspector Testrunnner
You can also use the Greenspector Meter Android API in continuous integration with
the Testrunner. To do so, you have to setup your Android Espresso or UIAutomator
tests with the Greenspector Probe just like in the previous section with little changes.
Indeed, you only need to initialize the *BASIC_SAMPLE_PACKAGE* and leave default values
in the *Probe configuration* of the code sample above and the rest will be handled by
the Testrunner.===
Samples
...
Android Test cases
...
Emma
.Ant
.Requirements
- Updated file ant.properties with the keystore informations
- Updated file local.properties with Android SDK informations
- Running GREENSPECTOR Server
...
adb pull /mnt/sdcard/greenspector/ /home/[user]/greenspectorData/====
Gradle
.Requirements
- Gradle project
- Gradle GREENSPECTOR file: greenspector-coverage.gradle
- Ant GREENSPECTOR file: greenspector-coverage-ant.xml
- Emma Android library: emma_device.jar
...
Code Block | ||||
---|---|---|---|---|
| ||||
<?xml version="1.0" encoding="UTF-8"?> <project> <property file="../local.properties" /> <!-- Emma configuration --> <property name="emma.dir" value="${sdk.dir}/tools/lib" /> <path id="emma.lib"> <pathelement location="${emma.dir}/emma.jar" /> <pathelement location="${emma.dir}/emma_ant.jar" /> </path> <taskdef resource="emma_ant.properties" classpathref="emma.lib" /> <!-- End of emma configuration --> <!-- Output directories --> <property name="out.dir" value="build" /> <property name="out.classes.absolute.dir" location="${out.dir}/intermediates/classes" /> <condition property="verbosity" value="verbose" else="quiet"> <istrue value="${verbose}" /> </condition> <!-- Instruments this project's .class files. --> <target name="instrument"> <echo message="Instrumenting classes from ${out.dir}/classes..."></echo> <property name="emma.coverage.absolute.file" location="${out.dir}/coverage.em" /> <!-- It only instruments class files, not any external libs --> <emma enabled="true"> <instr verbosity="${verbosity}" mode="overwrite" instrpath="${out.classes.absolute.dir}" outdir="${out.classes.absolute.dir}" metadatafile="${emma.coverage.absolute.file}"> </instr> </emma> </target> </project> |
...
UIAutomator Sample Project
If you are new to GREENSPECTOR for UiAutomator, try this sample first.
...
If you are using Android Studio, the Run window will show the test results.===
Usage
...
Test Cases
- I can send the measures in disconnected mode to the GSPT server and then retrieve them with using a command line from my PC to the server
- The test case launch automatically sends the coverage information to GREENSPECTOR
- I can send the coverage file by command line to GREENSPECTOR
- I can have the information on the resources but also on the objects with a meter running Android
- I can develop Android probe with a SDK