Skip to content

Commit 36b49f0

Browse files
authored
Merge pull request Azure#270 from kairu-ms/improve-docs
Update docs for `Command Usage and Testing`
2 parents bcbd992 + 81a69c0 commit 36b49f0

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

docs/pages/usage/command_usage_testing.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,47 @@ permalink: /pages/usage/command-usage-testing/
55
weight: 103
66
---
77

8-
## Overview
8+
## Command Usage
99

10-
Azure CLI provides two types of tests we can use: [unit tests](https://en.wikipedia.org/wiki/Unit_testing) and [integration tests](https://en.wikipedia.org/wiki/Integration_testing).
10+
### Before
1111

12-
For unit tests, we support unit tests written in the forms standard [unittest](https://docs.python.org/3/library/unittest.html).
12+
1. Make sure you have login by `az login`.
13+
2. Make sure you have set the subscription by `az account set -s {subscription ID for test}`.
14+
3. You can try to create a empty resource group by `az group create --name {your resource group name} --location westus` to check if you have the permission to the cloud.
15+
4. If your commands are in extensions, make sure you have loaded this extension by `azdev extension add {your extension name}`.
1316

14-
For integration tests, we provide the `ScenarioTest` and `LiveScenarioTest` classes to support replayable tests via [VCR.py](https://vcrpy.readthedocs.io/en/latest/).
17+
### Run your commands
1518

16-
Details about these two types of testing, env preparation, test policies and issue troubleshooting, please refer to the [doc](https://github.com/Azure/azure-cli/blob/dev/doc/authoring_tests.md)
19+
After that, you can directly try the generated command such as `az new-group-name new-command-name --the-arg value`.
1720

18-
After generating code from CodeGenV2, target cmd's test can be added into folder `path/to/your/cloned/azure-cli/target_mod`. Below is the demonstration of tests using azdev and [Pycharm Community](https://www.jetbrains.com/pycharm/download/#section=linux)
19-
### unit test
21+
There are some tips for you to use the generated command:
2022

21-
When first run unit test, use `--live` to access api and record `yaml` file for integration tests.
22-
```
23-
live mode: azdev test test_function_of_your_code --live
24-
non-live mode: azdev test test_function_of_your_code
25-
```
26-
For issues debugging, use `--debug` parameter appended the above cmd.
23+
1. You can add `--help` argument flag to get and verify the help information of the command. Such ass `az new-group-name new-command-name --the-arg value --help`
24+
2. For issue debugging, you can add `--debug` argument flag to print out the debug logs, which will contains all the http requests and responses, to help you triage the issue. If you need feature help from azure-cli team, please always provide this logs for us.
25+
3. The compound arguments generated supports [shorthand syntax](https://github.com/Azure/azure-cli/blob/dev/doc/shorthand_syntax.md) to input values.
2726

28-
For Pycharm Community, set env `Azure_TEST_RUN_LIVE` to be `true` for live mode and `false` for non-live mode.
27+
## Provide tests
2928

30-
![pycharm_env](../../assets/images/pycharm_live.png)
29+
It is required to providing tests for the change. Please reference this [doc](https://github.com/Azure/azure-cli/blob/dev/doc/authoring_tests.md) for details.
3130

32-
### intergration test
31+
Details about these two types of testing, env preparation, test policies and issue troubleshooting, please refer to the [doc](https://github.com/Azure/azure-cli/blob/dev/doc/authoring_tests.md)
3332

34-
Run tests for specific modules
35-
```
36-
azdev test {mod1} {mod2}
37-
```
38-
Re-run the tests that failed the previous run.
33+
After generating code from CodeGenV2, target cmd's test can be added into folder `path/to/your/cloned/azure-cli/target_mod`. Below is the demonstration of tests using azdev and [Pycharm Community](https://www.jetbrains.com/pycharm/download/#section=linux)
34+
35+
### Run tests
36+
37+
The `azdev test` command can help you run tests for your code, please check help message of `azdev test --help`.
38+
39+
When first run tests, use `--live` to make live request to apis and it will help record payloads in `yaml` file for CI playback validation.
3940
```
40-
azdev test --lf
41+
azdev test test_function_of_your_code --live
4142
```
42-
For more details about using `azdev`, please check message of `azdev test --help`
4343

44-
### Cmd usage
44+
For `Pycharm` users, please set env `Azure_TEST_RUN_LIVE` to be `true` for live mode and `false` for non-live mode.
45+
46+
![pycharm_env](../../assets/images/pycharm_live.png)
4547

46-
1. Before using the generated cmd, `az login` and `az account set -s your-subscription-id` should be set properly as noted [here](https://github.com/Azure/aaz-dev-tools#before-using-generated-commands)
47-
2. Run generated cmd `az your-module your-cmd`
48-
3. For issue debugging, please use `az your-module your-cmd --debug` to check the error and fix it. If more help or instruction needed, please leave a message to us with the error info printed in console.
48+
> **Note**
49+
>
50+
> When you record tests, please make sure the latest change of `dev` branch of **azure-cli** has been synced to your local repo.
51+
> Developers will always encounter this issue when the tests passed locally but failed in CI. This is because the api versions used by commands of **azure-cli** can be changed in `dev` branch. When the tests recorded in your local may uses out of date azure-cli commands, the recording will be failed in CI. That's why we need to sync the latest change of `dev` branch of **azure-cli** before recording tests.

0 commit comments

Comments
 (0)