iOS Testing Framework
Zendrive SDK testing framework allows developers to perform 'at-desk' integration testing for a variety of use cases and end-user scenarios. These include simulations for trip lifecycle, automatic trip detection, driving behavior events, and collisions.
Developers can test the application's UI components by receiving callbacks for a simulated trip without physically going for a drive. The testing workflow can then be rolled into a continuous integration (CI) pipeline.
This page outlines step-by-step instructions to integrate the Zendrive iOS Testing SDK into your application.
Integrate the Zendrive Testing Framework
Install via CocoaPods
The testing framework must not be shipped with the production application. We recommend that developers create a new target which uses the SDK testing framework.
We support only Objective-C for the testing framework.
Install CocoaPods. CocoaPods Guide.
Update CocoaPods. Our minimum supported version is
1.9.0
. See Known Issues.$ sudo gem update cocoapods
Create a Podfile and use it in Xcode. See Instructions.
Add the following to your Podfile and run
pod update
:pod 'ZendriveSDK/Testing', :git => 'https://bitbucket.org/zendrive-root/zendrive_cocoapod.git', :tag => '10.0.0'
Enable Testing Framework
1. Add the ZendriveMockModeEnabled
key to the Info.plist
file of the application with a value set to YES
(Boolean value).
2. Ensure that the SDK is enabled.
3. The testing framework only works when the trip detection mode is automatic. Hence, when initializing the SDK, set driveDetectionMode
to ZendriveDriveDetectionModeAutoON
.
Usage
Once the testing framework is enabled, developers can simulate the trip lifecycle. Developers can choose from a preset trip or create a custom trip. Once a simulation is triggered, the application will receive the configured callbacks automatically. Developers can also simulate the trip when the test app is in background.
Selecting Preset Trips
Zendrive recommends that developers simulate from a list of preset trips. Each preset trip has an in-built trip lifecycle with a selection of events.
Choose from a list of ZendrivePresetTripType
. The following are a selection from the available presets:
Urban10MinTrip
4445 meters
10 minutes
Hard brake, Aggressive acceleration
Highway60MinTrip
59112 meters
58 minutes
Hard brake, Overspeeding, Phone handling
Urban30MinWithCollisionTrip
50130 meters
31 minutes
Hard brake, Collision, Phone handling
The sample code illustrates how to build a ZendriveMockDrive
object for a preset Urban10MinTrip
.
#import <ZendriveSDKTesting/ZendriveMockDrive.h>
ZendriveMockDriveBuilder *mockDriveBuilder = [ZendriveMockDriveBuilder presetMockDrive:Urban10MinTrip];
ZendriveMockDrive *drive = [mockDriveBuilder build];
User can also modify a preset trip with app-specific use cases and then simulate a trip. This is useful when developers wish to modify trip distance or duration and add or remove events.
Running the Simulation
Once you have the ZendriveMockDrive
object, you can invoke the simulateDrive
event.
A configured trip might be very long. To complete testing within a shorter time frame, the simulation time must be specified in milliseconds.
// Ensure that SDK is setup and auto detection is ON before running the simulation.
NSError *error = nil;
[drive simulateDrive:30000 error:error]; //start receiving callbacks via delegate!
The application will then receive the processStartOfDrive:
, processEndOfDrive:
, processAnalysisOfDrive:
and processAccident:
callbacks at configured times.
Defining Custom Trips (Optional)
If developers need fine-grain control over mock trip definitions, the testing framework provides a ZendriveMockDriveBuilder
which can be used to set all trip parameters.
ZendriveMockDriveBuilder *builder = [ZendriveMockDriveBuilder newAutoDriveBuilderWithStartTimestamp:tripStartTs endTimestamp:tripEndTs];
[builder setAverageSpeed:5];
[builder setDriveType:ZendriveDriveTypeDrive];
// set waypoints
NSMutableArray *points = [[NSMutableArray alloc] init];
ZendriveLocationPoint point1 = [[ZendriveLocationPoint alloc] initWithTimestamp:locTimestamp latitude:locLatitude longitude:locLongitude];
[points addObject:point1];
[builder setWaypoints:points];
// set events
ZendriveMockAccidentEventBuilder *accidentBuilder = [[ZendriveMockAccidentEventBuilder alloc] initWithTimestamp:accidentTimestamp tripTimestamp:tripStartTs accidentId:@”mockAccident” confidence:ZendriveAccidentConfidenceHigh
];
[builder addEventBuilder:accidentBuilder];
// set delays
[builder setTripStartDelayMillis:1000];
[builder setTripEndDelayMillis:2000];
[builder setTripAnalysisDelayMillis:2000];
//build
ZendriveMockDrive *drive = [builder build];
//simulate
NSError *error = nil;
[drive simulateTrip:30000 error:error]; //start receiving callbacks via ZendriveDelegateProtocol!
Tips & Best Practices
The testing framework must not be shipped with the production application.
We recommend that developers create a new target which uses the SDK testing framework. This new target will have ZendriveSDK/Testing
instead of ZendriveSDK
listed as a dependency.
While the testing framework removes the necessity to go for a physical drive, we still recommend that you go for a drive to test the application.
The following features of Zendrive SDK cannot be tested using this framework. We plan to include these in future releases of the testing framework:
processResumeOfDrive
,processLocationDenied
,processLocationApproved
callbacksManual trip lifecycle
ZendriveInsurance
andZendriveFeedback
APIs
Was this helpful?