If you want to write a test case or an example that supports the mock testing framework you must create a client with a transaction name that matches a collection of transactions found in the "tests/transactions" directory at the root of the SDK workspace.
For instance in cosmos
you can use the CosmosClient::new_with_transaction
function.
let account = "MyCosmosAccountName";
let context = cosmos::CosmosClient::new(account, "create_database_and_collection");
NOTE: This requires that the mock_transport_framework
feature is enabled. Otherwise the above code will not compile.
The above code expects there to be a create_database_and_collection
subdirectory in the tests/transactions
directory. This directory will contain all the outgoing requests and incoming responses for the example or test.
Instead of writing the request and response json files by hand, you can simply record a run of the example or test against live services. This ensures that the requests and responses are valid, working requests and responses. You can do this like so:
- Execute the example/test with the
mock_transport_framework
feature enabled. - Export the environmental variable
TESTING_MODE
with the value ofRECORD
.
For example:
TESTING_MODE=RECORD cargo test create_database_and_collection --features=mock_transport_framework
Once there are request and response json files in the correct transaction folder, you can easily run the example or test against the locally stored requests and responses (instead of a live Azure cloud) like so:
- Execute the example/test with the
mock_transport_framework
feature enabled. - Make sure the environmental variable
TESTING_MODE
is either not set or set with the value ofREPLAY
.
For example:
TESTING_MODE=REPLAY cargo test create_database_and_collection --features=mock_transport_framework
The mock testing framework supports the pipeline architecture only. For this reason we cannot migrate the E2E test cases until the pipeline migration has been completed.
Most available E2E test can and will support the new testing framework. While the mock testing framework will never replace proper testing against Azure, the mock framework will enable quick, reproducible tests.