You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
11
11
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}`.
13
16
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
15
18
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`.
17
20
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:
20
22
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.
27
26
28
-
For Pycharm Community, set env `Azure_TEST_RUN_LIVE` to be `true` for live mode and `false` for non-live mode.
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.
31
30
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)
33
32
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.
39
40
```
40
-
azdev test --lf
41
+
azdev test test_function_of_your_code --live
41
42
```
42
-
For more details about using `azdev`, please check message of `azdev test --help`
43
43
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.
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