0
# Test Administration
1
2
Complete management of load test definitions, test scripts, and configuration through the LoadTestAdministrationClient. This includes creating and updating test definitions, uploading JMeter scripts and supporting files, configuring application components for monitoring, and setting up server-side metrics collection.
3
4
## Capabilities
5
6
### Test Management
7
8
Create, update, retrieve, and delete load test definitions. Tests define the basic configuration including display name, description, engine instances, and pass/fail criteria.
9
10
```python { .api }
11
def create_or_update_test(test_id: str, body: Union[JSON, IO], **kwargs) -> JSON:
12
"""
13
Create a new test or update an existing test.
14
15
Parameters:
16
- test_id (str): Unique name for the load test (2-50 chars, lowercase alphanumeric, underscore, hyphen)
17
- body (Union[JSON, IO]): Load test definition
18
19
Returns:
20
JSON: Test definition with metadata
21
"""
22
23
def delete_test(test_id: str, **kwargs) -> None:
24
"""
25
Delete a test by its ID.
26
27
Parameters:
28
- test_id (str): Unique test identifier
29
"""
30
31
def get_test(test_id: str, **kwargs) -> JSON:
32
"""
33
Get load test details by ID.
34
35
Parameters:
36
- test_id (str): Unique test identifier
37
38
Returns:
39
JSON: Test definition with metadata
40
"""
41
42
def list_tests(
43
*,
44
orderby: Optional[str] = None,
45
search: Optional[str] = None,
46
last_modified_start_time: Optional[datetime] = None,
47
last_modified_end_time: Optional[datetime] = None,
48
**kwargs
49
) -> Iterable[JSON]:
50
"""
51
List all load tests with optional filtering.
52
53
Parameters:
54
- orderby (str, optional): Sort order ("lastModifiedDateTime asc" or "lastModifiedDateTime desc")
55
- search (str, optional): Search filter by displayName or createdBy
56
- last_modified_start_time (datetime, optional): Filter by last modified start time
57
- last_modified_end_time (datetime, optional): Filter by last modified end time
58
59
Returns:
60
Iterable[JSON]: Paginated list of test definitions
61
"""
62
```
63
64
#### Example: Creating a Load Test
65
66
```python
67
from azure.core.credentials import DefaultAzureCredential
68
from azure.developer.loadtesting import LoadTestAdministrationClient
69
70
credential = DefaultAzureCredential()
71
client = LoadTestAdministrationClient(
72
endpoint="https://your-resource.loadtest.azure.com",
73
credential=credential
74
)
75
76
# Define test configuration
77
test_definition = {
78
"displayName": "API Performance Test",
79
"description": "Load test for REST API endpoints",
80
"loadTestConfiguration": {
81
"engineInstances": 1,
82
"splitAllCSVs": False
83
},
84
"passFailCriteria": {
85
"passFailMetrics": {
86
"response_time_95": {
87
"clientMetric": "response_time_ms",
88
"aggregate": "percentage",
89
"condition": "<=",
90
"value": 1000.0
91
}
92
}
93
}
94
}
95
96
with client:
97
test = client.create_or_update_test("api-perf-test", test_definition)
98
print(f"Created test: {test['displayName']}")
99
```
100
101
### Test File Management
102
103
Upload, retrieve, and manage test files including JMeter scripts, CSV data files, and other supporting files. Files can be up to 50 MB in size.
104
105
```python { .api }
106
def begin_upload_test_file(
107
test_id: str,
108
file_name: str,
109
body: IO,
110
*,
111
file_type: Optional[str] = None,
112
**kwargs
113
) -> JSON:
114
"""
115
Upload input file for a test.
116
117
Parameters:
118
- test_id (str): Unique test identifier
119
- file_name (str): Name of the file to upload
120
- body (IO): File content as binary stream
121
- file_type (str, optional): File type ("JMX_FILE", "USER_PROPERTIES", "ADDITIONAL_ARTIFACTS")
122
123
Returns:
124
JSON: File metadata including validation status
125
"""
126
127
def get_test_file(test_id: str, file_name: str, **kwargs) -> JSON:
128
"""
129
Get test file metadata.
130
131
Parameters:
132
- test_id (str): Unique test identifier
133
- file_name (str): Name of the file
134
135
Returns:
136
JSON: File metadata including validation status
137
"""
138
139
def delete_test_file(test_id: str, file_name: str, **kwargs) -> None:
140
"""
141
Delete a test file.
142
143
Parameters:
144
- test_id (str): Unique test identifier
145
- file_name (str): Name of the file to delete
146
"""
147
148
def list_test_files(test_id: str, **kwargs) -> Iterable[JSON]:
149
"""
150
List all files for a test.
151
152
Parameters:
153
- test_id (str): Unique test identifier
154
155
Returns:
156
Iterable[JSON]: List of file metadata
157
"""
158
```
159
160
#### Example: Uploading Test Files
161
162
```python
163
with client:
164
# Upload JMeter test script
165
with open("load-test.jmx", "rb") as jmx_file:
166
upload_result = client.begin_upload_test_file(
167
test_id="my-test",
168
file_name="load-test.jmx",
169
body=jmx_file,
170
file_type="JMX_FILE"
171
)
172
print(f"Upload status: {upload_result['validationStatus']}")
173
174
# Upload CSV data file
175
with open("test-data.csv", "rb") as csv_file:
176
upload_result = client.begin_upload_test_file(
177
test_id="my-test",
178
file_name="test-data.csv",
179
body=csv_file,
180
file_type="ADDITIONAL_ARTIFACTS"
181
)
182
183
# List all files for the test
184
files = list(client.list_test_files("my-test"))
185
for file_info in files:
186
print(f"File: {file_info['fileName']} - Status: {file_info['validationStatus']}")
187
```
188
189
### Application Components Configuration
190
191
Configure Azure resources to monitor during load testing. This enables collection of server-side metrics like CPU usage, memory consumption, and custom application metrics during test execution.
192
193
```python { .api }
194
def create_or_update_app_components(test_id: str, body: Union[JSON, IO], **kwargs) -> JSON:
195
"""
196
Create or update app components configuration for a test.
197
198
Parameters:
199
- test_id (str): Unique test identifier
200
- body (Union[JSON, IO]): App components configuration
201
202
Returns:
203
JSON: App components configuration
204
"""
205
206
def get_app_components(test_id: str, **kwargs) -> JSON:
207
"""
208
Get app components configuration for a test.
209
210
Parameters:
211
- test_id (str): Unique test identifier
212
213
Returns:
214
JSON: App components configuration
215
"""
216
```
217
218
#### Example: Configuring App Components
219
220
```python
221
app_components = {
222
"components": {
223
"web-app": {
224
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Web/sites/my-webapp",
225
"resourceName": "my-webapp",
226
"resourceType": "Microsoft.Web/sites",
227
"kind": "web"
228
},
229
"sql-db": {
230
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Sql/servers/my-server/databases/my-db",
231
"resourceName": "my-db",
232
"resourceType": "Microsoft.Sql/servers/databases",
233
"kind": "database"
234
}
235
}
236
}
237
238
with client:
239
components = client.create_or_update_app_components("my-test", app_components)
240
print(f"Configured {len(components['components'])} app components")
241
```
242
243
### Server Metrics Configuration
244
245
Configure server-side metrics collection for Azure resources during load testing. This enables monitoring of infrastructure performance alongside client-side load testing metrics.
246
247
```python { .api }
248
def create_or_update_server_metrics_config(test_id: str, body: Union[JSON, IO], **kwargs) -> JSON:
249
"""
250
Create or update server metrics configuration for a test.
251
252
Parameters:
253
- test_id (str): Unique test identifier
254
- body (Union[JSON, IO]): Server metrics configuration
255
256
Returns:
257
JSON: Server metrics configuration
258
"""
259
260
def get_server_metrics_config(test_id: str, **kwargs) -> JSON:
261
"""
262
Get server metrics configuration for a test.
263
264
Parameters:
265
- test_id (str): Unique test identifier
266
267
Returns:
268
JSON: Server metrics configuration
269
"""
270
```
271
272
#### Example: Configuring Server Metrics
273
274
```python
275
server_metrics_config = {
276
"metrics": {
277
"web-app-cpu": {
278
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Web/sites/my-webapp",
279
"metricNamespace": "Microsoft.Web/sites",
280
"name": "CpuPercentage",
281
"aggregation": "Average",
282
"unit": "Percent"
283
},
284
"sql-dtu": {
285
"resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Sql/servers/my-server/databases/my-db",
286
"metricNamespace": "Microsoft.Sql/servers/databases",
287
"name": "dtu_consumption_percent",
288
"aggregation": "Average",
289
"unit": "Percent"
290
}
291
}
292
}
293
294
with client:
295
metrics_config = client.create_or_update_server_metrics_config("my-test", server_metrics_config)
296
print(f"Configured {len(metrics_config['metrics'])} server metrics")
297
```
298
299
## Async Operations
300
301
All administration operations have async equivalents available in `azure.developer.loadtesting.aio.LoadTestAdministrationClient`:
302
303
```python
304
from azure.developer.loadtesting.aio import LoadTestAdministrationClient
305
from azure.core.credentials_async import DefaultAzureCredential
306
307
async def manage_tests():
308
credential = DefaultAzureCredential()
309
client = LoadTestAdministrationClient(
310
endpoint="https://your-resource.loadtest.azure.com",
311
credential=credential
312
)
313
314
async with client:
315
# Create test
316
test = await client.create_or_update_test("my-test", test_definition)
317
318
# Upload file
319
with open("test.jmx", "rb") as f:
320
result = await client.begin_upload_test_file("my-test", "test.jmx", f)
321
322
# List tests
323
async for test in client.list_tests():
324
print(f"Test: {test['displayName']}")
325
```