Rough guidance on record playback.

Travis Prescott 2021-07-20 15:10:33 -07:00
Родитель 1061c715e0
Коммит b3fd328655
1 изменённых файлов: 25 добавлений и 0 удалений

@ -0,0 +1,25 @@
`AzureTest` is a framework written to help Azure SDK developers write tests for Swift that can be recorded and played back without network connectivity. It leverages a customized fork of the `Venmo/DVR` framework, which itself is based on the popular Ruby `VCR` framework.
## Getting Started
1. Within your framework's main target, add `AzureTest.framework` under `General > Frameworks and Libraries`.
2. In `Package.swift`, add `AzureTest` to the dependencies for your test target.
## Creating Resources
Most tests require some Azure resources to be set up prior to running, and these resources should be cleaned up after the test completes. Mechanisms exists to facilitate this automatically.
1. Within the service folder for your framework (the folder directly beneath `sdk`), add resources to either the `test-resources.bicep` file or `test-resources.json`. This file will be used to deploy resources when your test is run live.
2. If you need to do further setup with the resources created in step 1, add or modify the `test-resources-pre.ps1` or `test-resources-post.ps1` scripts to perform any necessary setup. By default, you can only use Powershell cmdlets. The necessary outputs from these scripts should be dumped into a file called `test-settings.plist` (see below).
## Storing Credentials
1. Create a class which implements `AzureTest.TestSettingsProtocol`. This model should consist of string-based properties which back credentials you need to supply to run tests live.
2. Within your `Tests` folder, create a plist file named `test-settings.plist` (MUST be an exact match) and add it to the project. This file is part of the `.gitignore` and thus will not be committed as a change in source control.
3. Within the `setUp` or `setUpWithError` methods of your test class, load your settings by invoking the static `loadFromPlist()` method from your settings model type. This will deserialize the contents of `test-settings.plist` and make the values available for use in your test.
## Writing Tests
1. Within the `Tests` folder, create a new "Unit Test Case Class" in Xcode and import `AzureTest` along with any other necessary imports.
2. Load your test settings as described above and use those values to create any client you need.
3. Load the value of the environment variable `TEST_MODE` by writing: `private var mode = environmentVariable(forKey: "TEST_MODE", default: "playback")`. If the value is anything except "live", pass along a `DVRSessionTransport` object in the `TransportOptions` passed to the client.