Mobile API virtualization using SV Lab

The SV Lab supports virtualization of various mobile APIs enabling automated testing of mobile applications depending on physical devices connected over Bluetooth LE GATT or requiring physical manipulation (NFC tag reading).

The simulation models can be learned from real device interaction.

BLE GATT is an acronym for Bluetooth Low Energy Generic Attribute Protocol. You can learn more at

NFC is an acronym for Near Field Communication. SV Lab supports use cases where the application emulates an NFC-enabled card using the HCE API (Host-based Card Emulation). For more information, see

This section describes the general workflow and the configuration steps required to perform the virtualization. There are two samples dedicated to virtualization of Bluetooth LE GATT device (demo/gadgetbridge) and NFC payment card reader (demo/bestwallet) available in the SV Lab distribution.

Some mobile API related scenarios can be learned and simulated with the .NET Service Virtualization. For details, see BLE GATT and NFC support.

How Service Virtualization Simulation over BLE GATT and NFC Works

Back to top

The Workflow

The following are the steps required for simulating the device:

  1. Configure the device to talk to SV Lab.
  2. Package the Android application to test using code that enables virtualization of smart devices connected over BLE GATT.
  3. Install the packaged app on the device.
  4. Learn and/or design the simulation models.
  5. Simulate the device to test the application without physically accessing the device.


  • Java JDK 1.7 or newer.
  • Either Mobile Center or the ADB tool to upload APKs to the device. The ADB tool can be installed either with the Android Studio or the light-weight Minimal ADB And Fastboot distribution.
  • A device with Android 5.0 Lollipop or newer with USB debugging enabled.
  • A SV Lab Server running on local host (launched with|.bat)
  • The physical BLE GATT device or NFC card reader for model learning.

Before you begin, integrate SV Lab into your application tests. See Configure and run virtual lab or use one of the Mobile API demos (demo/gadgetbridge or demo/bestwallet) as a template.

The examples that follow assume that your projects folder is under the demo directory. For a different location, update the paths in the command lines accordingly.

Back to top

Step 1: Android Connector Configuration

You need to configure the Android device to connect to your PC running the simulation. There has to be a virtual lab running to test the connection. You can use the sv-capture tool to bring it up. For example,

On Linux:

../../bin/ -u https://localhost:8445/api/ -c MOBILE_API -p 9009 \
-d ./sandbox

On Windows:

..\..\bin\sv-capture.bat -u https://localhost:8445/api/ -c MOBILE_API -p 9009 ^
-d ./sandbox

Now install the SV Connector application on the device. If you work with a device connected to Mobile Center, upload the ../../bin/sv-android-connector-5.00.apk file and install it on the device using Mobile Center. Alternatively, use the Android SDK's ADB tool to install the application on a device connected with a USB cable:

On Linux:

adb install ../../bin/sv-android-connector-5.00.apk

On Windows:

adb install ..\..\bin\sv-android-connector-5.00.apk

Launch the SV Connector application on your device and enter the IP address or host name of your PC. The application tests the connection to the running lab. Make sure it shows the OK status:

Now stop the virtual lab by pressing the <Enter> key in the console window where you ran the sv-capture tool.

Back to top

Step 2: Android Application Virtualization

The SV Lab needs to hook-in to the Android application to be tested so it can learn and simulate the Bluetooth API calls used to communicate with the Bluetooth device or NFC card reader. It is performed by packaging the mobile application with the Mobile Center’s APKInfuser tool using code that enables the virtualization of physical devices connected over BLE GATT or NFC HCE interfaces.

Get the ApkInfuser tool from the Micro Focus AppDelivery Marketplace. Download the APKInfuser - Android app packager 2.53 package and extract the ZIP file to the SV Lab bin directory.

Then execute following command in demo directory:

On Linux:

../../bin/ -custom ../../bin/sv-ble.json \
../../bin/sv-ble.dex -signdebug mobileapp.apk

On Windows:

..\..\bin\MCAndroidEnabler.bat -custom ..\..\bin\sv-ble.json ^
..\..\bin\sv-ble.dex -signdebug mobileapp.apk

When you use mobileapp.apk as an input, you generate a packaged version of the application, mobileapp.apk.signed.debug.apk.

There are different configuration files depending on the virtualized mobile API. Make sure to use the appropriate .json and .dex files during packaging:

For the Bluetooth LE GATT virtualization:

-custom ../../bin/sv-ble.json ../../bin/sv-ble.dex

For the NFC HCE (card reader) virtualization:

-custom ../../bin/nfc-hce.json ../../bin/nfc-hce.dex

Back to top

Step 3: Install the Packaged Application

First, uninstall the non-packaged version of the application from the device. Then install the packaged application on the device through Mobile Center or with the ADB tool:

adb install mobileapp.apk.signed.debug.apk

Back to top

Step 4: Design Or Learn Simulation Models

When you work with a new device or when you create new tests you have to create simulation models with new scenarios describing the desired behavior of the device during test cases.

With Bluetooth devices, the most common way is to learn each scenario while interacting with real device and then add it to your simulation models. The detailed flow of learning and editing the learned models is described in the demo/gadgetbridge sample.

With NCF HCE, the interaction is simpler. You can use the demo/bestwallet sample as a template for your simulation and modify the demo models.

Use the sv-capture tool to learn the interaction:

On Linux:

../../bin/ -u https://localhost:8445/api/ -c MOBILE_API -p 9009 \
-d ./sandbox

On Windows:

..\..\bin\sv-capture.bat -u https://localhost:8445/api/ -c MOBILE_API -p 9009 ^
-d ./sandbox

The tool brings up a virtual lab with virtual service ready for learning. Wait until the capture scenario starts. This can take a few seconds when you are learning for the first time:

Service: http://localhost:9000/
Press <Enter> to stop...
09:13:54.263 [Thread-1] INFO [SV_RUNLOG] - Lab transition NOT_DEPLOYED -> INITIALIZED has succeeded.
09:13:54.263 [Thread-1] INFO [SV_RUNLOG] - Lab transition INITIALIZED -> STARTED has succeeded.
09:13:54.263 [Thread-1] INFO [SV_RUNLOG] - Scenario has started: capture

Now perform the desired interaction between the mobile application and the virtualized device. You can see the captured messages in the sv-capture tool.

Finish the learning by pressing <Enter> in the sv-capture tool. The resulting VSL files containing the learned scenario are written to the sandbox directory:


Copy the important calls or whole scenario from MobileApiServiceModel.js to your project. The learning/refactoring/simulation workflow is documented in the demo/gadgetbridge sample.

Back to top

Step 5: Simulation

Depending on the integration with your testing project, the simulation is either started during test initialization or, when you have used one of the demos as a project template, you can launch the scenarios you’ve designed with a script:

On Linux:

./ <scenario_name>

On Windows:

run-with-server.bat <scenario_name>

Check the console for the Scenario has started <scenario_name> message. Launch the application on your device and repeat the test case. You can finish the simulation of one scenario pressing the <Enter> key at any time and run a different scenario using the same command.

Press <Enter> to quit simulation.
12:16:27 INFO [SV_RUNLOG] - Lab transition NOT_DEPLOYED -> INITIALIZED has succeeded.
12:16:27 INFO [SV_RUNLOG] - Lab transition INITIALIZED -> STARTED has succeeded.
12:16:27 INFO [SV_RUNLOG] - Scenario has started: <scenario_name>

Back to top