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
Copy file name to clipboardExpand all lines: documentation/Quickstart-on-how-to-write-tests.md
+39-6Lines changed: 39 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,15 +58,42 @@ If you have no concepts of `recording`, `playback` or [TEST_MODE](https://github
58
58
59
59
## Code structure
60
60
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.
62
62
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
+
});
65
92
```
66
93
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:
68
95
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._
70
97
71
98
```
72
99
sdk/
@@ -84,9 +111,13 @@ sdk/
84
111
│ │ │ | ├─ sampleTest.spec.ts
85
112
```
86
113
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
+
87
118
## Run tests in record mode
88
119
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.
90
121
91
122
```Shell
92
123
> pnpm install
@@ -114,6 +145,8 @@ If you are the first time to run tests you may fail with below message because t
114
145
115
146
To record or update our recordings, we need to set the environment variable `TEST_MODE` to `record`. Then, run `pnpm test`.
116
147
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)
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.
40
40
@@ -47,6 +47,7 @@ See the [Javascript Codegen Quick Start for Test](https://github.com/Azure/azure
47
47
Also, you could refer to the below examples for more cases:
0 commit comments