Skip to content

Commit 8598e04

Browse files
kazrael2119Copilot
andauthored
[docs] improve the testing part of Quickstart-on-how-to-write-tests.md doc (#36289)
imporve docs for the testing part --------- Co-authored-by: Copilot <[email protected]>
1 parent dfa5a07 commit 8598e04

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

documentation/Quickstart-on-how-to-write-tests.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,42 @@ If you have no concepts of `recording`, `playback` or [TEST_MODE](https://github
5858

5959
## Code structure
6060

61-
If you are the first time to generate SDK you could enable the config `generate-test: true` in `README.md`. We'll generate simple utils and a sample test file for you.
61+
If this is your first time generating an SDK, you can enable the config `generate-test: true` in `README.md` or `tspconfig.yaml`. For management plane packages, `generate-test` is always enabled. Then we'll generate simple utils and a sample test file for you.
6262

63-
```yml
64-
generate-test: true
63+
```
64+
// Copyright (c) Microsoft Corporation.
65+
// Licensed under the MIT License.
66+
67+
// import type { Recorder } from "@azure-tools/test-recorder";
68+
// import { createRecorder } from "./utils/recordedClient.js";
69+
import {
70+
assert,
71+
// beforeEach,
72+
// afterEach,
73+
it,
74+
describe,
75+
} from "vitest";
76+
77+
describe("My test", () => {
78+
// let recorder: Recorder;
79+
80+
// beforeEach(async function (ctx) {
81+
// recorder = await createRecorder(ctx);
82+
// });
83+
84+
// afterEach(async function () {
85+
// await recorder.stop();
86+
// });
87+
88+
it("sample test", async function () {
89+
assert.equal(1, 1);
90+
});
91+
});
6592
```
6693

67-
They only contains basics for testing, you need to update to your own utility and test cases. The overall structure will be similar to below:
94+
This only contains basics for testing, we comment out some lines **except** licence header. If you want to update to your own utility and test cases. The overall structure will be similar to below:
6895

69-
_Note: the structure of the `test` folder has slight differences between high-level and rest-level clients. In HLC, we only have one file under the `test` folder which contains all contents. But in RLC, we separate the sample test and utils._
96+
_Note: the structure of the `test` folder has slight differences between high-level, rest-level and Modular clients. In HLC, we only have one file under the `test` folder which contains all contents. But in RLC and Modular, we separate the sample test and utils._
7097

7198
```
7299
sdk/
@@ -84,9 +111,13 @@ sdk/
84111
│ │ │ | ├─ sampleTest.spec.ts
85112
```
86113

114+
You could also refer [here](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/steps-after-generations.md#how-to-write-test-for-dpgrlcmpg) to add your test cases.
115+
116+
After writing your test cases you need to run your test cases and record the test recordings. See [here](#run-tests-in-record-mode)
117+
87118
## Run tests in record mode
88119

89-
Before running tests, it's advised to update the dependencises and build our project by running the command `pnpm install && pnpm build --filter=<package-name>...`. Please notice this command is time-consuming and it will take around 10 mins, you could refer [here](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md#resolving-dependency-version-conflicts) for more details.
120+
Before running tests, it's advised to update the dependencies and build our project by running the command `pnpm install && pnpm build --filter=<package-name>...`. Please notice this command is time-consuming and it will take around 10 mins, you could refer [here](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md#resolving-dependency-version-conflicts) for more details.
90121

91122
```Shell
92123
> pnpm install
@@ -114,6 +145,8 @@ If you are the first time to run tests you may fail with below message because t
114145

115146
To record or update our recordings, we need to set the environment variable `TEST_MODE` to `record`. Then, run `pnpm test`.
116147

148+
After running the test cases, you need to push your recordings into assets repo. See [here](#how-to-push-test-recordings-to-assets-repo)
149+
117150
```Shell
118151
# Windows
119152
> set TEST_MODE=record

documentation/steps-after-generations.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ A minimal README.md is generated by TypeScript emitter and you could improve REA
3434
- RLC example: [Maps Route README.md](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/maps/maps-route-rest/README.md)
3535
- DPG example: [OpenAI README.md](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/openai/openai/README.md)
3636

37-
# How to write test for DPG/RLC
37+
# How to write test for DPG/RLC/MPG
3838

3939
In order to release it, we need to add some tests for it to make sure we are delivering high quality packages. After generation you will see a `sampleTest.spec.ts` file in your `{PROJECT_ROOT}/test/public` folder, which has an empty test and you could add/update test cases against your own services.
4040

@@ -47,6 +47,7 @@ See the [Javascript Codegen Quick Start for Test](https://github.com/Azure/azure
4747
Also, you could refer to the below examples for more cases:
4848
- RLC example: [OpenAI Testing](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/test/public)
4949
- DPG example: [Maps Route Testing](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/maps/maps-route-rest/test/public)
50+
- MPG example: [Containerservice Fleet Testing](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/containerservice/arm-containerservicefleet/test/public/)
5051

5152
2. **Run the test**
5253

0 commit comments

Comments
 (0)