Measure the resource consumption of an application via automated tests

Reading Time: 2 minutes

Some indications are needed to start a good energy and ressource measure with GREENSPECTOR. Three notions must be taken into account: where will be run the tests (WHERE), what are the tests that I’m going to run (WHAT) et how am I going to run these tests (HOW).

Several ways to launch these tests (HOW) are available:

  • From the GREENSPECTOR web interface
  • From the command line with the Test Runner
  • From the command line with the CLI
  • Manually with the Free Runner Test
  • From the Jenkins Plugin

Measure the resource consumption of an application via automated tests

To better characterize the consumption of an application, you can integrate the GREENSPECTOR API into your automated tests. You will be able to run tests from your usual environment or from the GREENSPECTOR Android Test Runner on your local phone. After that, you’ll be able to use his tests on the Power Test Cloud.

1) Download the Android API GREENSPECTOR (Meter API Android) on the list of modules and examples.

2) Install the AAR library in your Maven directory:

mvn install:install-file
-Dfile=greenspector-probe-android-[version].aar
-DgroupId=com.greenspector.probe.android
-DartifactId=greenspector-probe-android
-Dversion=[version]
-Dpackaging=aar

3) Unpack the examples

4) Open the UIAutomator project in Android Studio

5) Open the GreenspectorUIAutomator.java file and edit the following information:

  • APPLICATION: Same name as that set in the GREENSPECTOR interface;
  • VERSION: Same version as configure in the GREENSPECTOR interface;
  • URL: URL of your instance “https://my-instance.greenspector.com/api“;
  • PRIVATETOKEN: Your token found in your preferences from your GREENSPECTOR interface

6) Connect your phone to the same Wifi network as your platform

7) In a CLI, type the following command:

adb tcpip 5555

8) Unplug the cable and find the IP address of your smartphone in the settings.

9) Connect to phones with the following command:

adb connect [IP]

10) Right click on the class GreenspectorUIAutomator and start the test (Run …).

The test is launched on your mobile, you will find the results of your measurements within your GREENSPECTOR interface.

Discover our others tutorials :