Skip Navigation

Automated testing with the 
BlackBerry Dynamics
 sample apps

The sample apps included in the 
BlackBerry Dynamics SDK
 have been integrated with the 
BlackBerry Dynamics
 Automated Test Support Library (ATSL). Each sample app includes test code that executes automated tests of processing and behavior.
You can use the integration of the ATSL in any sample app as a guide for integrating the library with your own 
BlackBerry Dynamics
 apps. Note the following details about the ATSL integration:
Item
Description
Build target for testing
Each app has an 
androidTest
 build target that the 
Android
 Plugin for 
Gradle
 can use. For more information about the 
Android
 Plugin for 
Gradle
, see Android Studio: Configure your build.
Code for JUnit tests
The test code is located in the sub-directory 
<sample_app>
/tests/
<sample_app_package>
/test/.
The code is based on JUnit4. You can run tests with 
AndroidJUnitRunner
Use of ATSL for interaction with 
BlackBerry Dynamics
 screens
The test code uses helper functions in the ATSL. For example, the following code executes the entire activation process for the app:
BBDActivationHelper.
loginOrActivateApp
()
The user's email, access key, and password are read from a file in JSON format (see Preparing for automated testing).
You can run ATSL helper functions in the JUnit assertion programming interface. For example:
assertTrue
("Failed to provision AppKinetics sample app.", BBDActivationHelper.
loginOrActivateApp
());
This assertion will fail if activation fails.
Each 
BlackBerry Dynamics
 screen is represented by an object that provides convenient methods to interact with the UI elements that it consists of.
You can use the following snippet to enter user credentials and start the activation process using credentials that are not stored in the JSON file: 
BBDActivationUI activationScreen = new BBDActivationUI(
uiAutomatorUtils
.getAppPackageName()); activationScreen.enterUserLogin("email@example.com"); activationScreen.enterKey("12345", "12345", "12345"); activationScreen.clickOK();
Use of ATSL for general interactions
The test code also uses helper functions in the ATSL for general interactions (for example, checking that an item exists in the user interface and then interacting with that item). See the following example:
uiAutomatorUtils
.isTextShown("Retrieving data");
The ATSL functions handle this by using UIAutomator.
Broadcast receiver for authorization events
The test code registers a broadcast receiver that receives authorization events from the 
BlackBerry Dynamics SDK
:
GDAndroid.getInstance().registerReceiver (GDSDKStateReceiver.getInstance(), GDSDKStateReceiver.getInstance().getIntentFilter());
Broadcast receiver registration supports multiple receiver classes and doesn’t block 
GDStateListener
 or 
GDAppEventListener
 implementations, if any. The broadcast receiver code is in the 
GDSDKStateReceiver
 class.