mirror of
https://github.com/ProtonMail/protoncore_android.git
synced 2026-06-14 09:54:49 +00:00
Mock Proxy SDK
Mock proxy SDK allows to control mock proxy server parameters from inside your test.
Supported features:
- Single route mock.
- Scenario mocking (collection of routes).
- Control bandwidth.
- Control latency.
Start using
To start using SDK create an instance of MockClient(baseUrl: String):
val mockClient = MockClient(baseUrl)
Here baseUrl can be an atlas environment or the local host URL.
If you run tests locally using emulator use Android localhost baseUrl value from Constants:
public const val EMULATOR_LOCALHOST: String = "http://10.0.2.2:3001/"
MockClient instance creation with pre-defined local host value for Android emulator:
val mockClient = MockClient(EMULATOR_LOCALHOST)
Mock single route
SDK assumes mock files are stored in app or test assets.
Mock single route from app assets:
mockClient.setStaticMockFromAppAssets(routeFilePath)
Mock single route from test assets:
mockClient.setStaticMockFromTestAssets(routeFilePath)
Mock scenario
Mock scenario route from app assets (both app and test assets):
mockClient.setScenarioFromAssets(scenarioFilePath)
Reset scenario from app assets:
mockClient.resetScenarioFromAppAssets(scenarioFilePath)
Reset scenario from test assets:
mockClient.resetScenarioFromTestAssets(scenarioFilePath)
Get, set and reset latency
val latencyInfo = mockClient.getLatency()
mockClient.setLatency(LatencyLevel.HIGH)
mockClient.resetLatency()
Get, set and reset bandwidth
val bandwidth = mockClient.getBandwidth()
mockClient.setBandwidth(BandwidthLimit._4G)
mockClient.resetBandwidth()
Resetting the state (reset all)
mockClient.resetAllMocks()