• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 开发自测试执行框架
2OpenHarmony为开发者提供了一套全面的开发自测试框架OHA-developertest,开发者可根据测试需求开发相关测试用例,开发阶段提前发现缺陷,大幅提高代码质量。
3
4本文从基础环境构建,用例开发,编译以及执行等方面介绍OpenHarmony开发自测试执行框架如何运行和使用。
5## 基础环境构建
6开发自测试框架依赖于python运行环境,python版本为3.8.X,在使用测试框架之前可参阅以下方式进行配置。
7 - [环境配置](https://gitee.com/openharmony/docs/tree/master/zh-cn/device-dev/subsystems/subsys-testguide-envbuild.md)
8 - [源码获取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/sourcecode-acquire.md)
9
10开发自测试框架依赖于测试调度框架test_xdevice,在使用时两个框架放在同级目录,命名为xdevice
11
12## 开发自测试框架目录简介
13以下是开发自测试框架的目录层级架构,在使用开发自测试框架过程中可在相应目录查找对应组件。
14```
15test  # 测试子系统
16├── developertest  # 开发者自测试框架
17│   ├── aw  # 测试框架的静态库
18│   ├── config  # 测试框架配置
19│   │   │ ...
20│   │   └── user_config.xml  # 用户使用配置
21│   ├── examples  # 测试用例示例
22│   ├── src  # 测试框架源码
23│   ├── third_party  # 测试框架依赖第三方组件适配
24│   ├── reports  # 测试结果报告
25│   ├── BUILD.gn  # 测试框架编译入口
26│   ├── start.bat  # 开发者测试入口(Windows)
27│   └── start.sh  # 开发者测试入口(Linux)
28└── xdevice  # 测试框架依赖组件
29```
30## 功能特性
31
32### 测试用例
33
34####  测试用例目录规划
35使用测试框架过程中,可根据以下层级关系规划测试用例目录。
36
37```
38subsystem  # 子系统
39├── partA  # 部件A
40│   ├── moduleA  # 模块A
41│   │   ├── include
42│   │   ├── src  # 业务代码
43│   │   └── test  # 测试目录
44│   │       ├── unittest  # 单元测试
45│   │       │   ├── common  # 公共用例
46│   │       │   │   ├── BUILD.gn  # 测试用例编译配置
47│   │       │   │   └── testA_test.cpp  # 单元测试用例源码
48│   │       │   ├── phone  # 手机形态用例
49│   │       │   ├── ivi  # 车机形态用例
50│   │       │   └── liteos-a  # ipcamera使用liteos内核的用例
51│   │       ├── moduletest  # 模块测试
52│   │       ...
53│   │
54│   ├── moduleB  # 模块B
55│   ├── test
56│   │   └── resource  # 依赖资源
57│   │       ├── moduleA  # 模块A
58│   │       │   ├── ohos_test.xml  # 资源配置文件
59│   │       ... └── 1.txt  # 资源
60│   │
61│   ├── ohos_build  # 编译入口配置
62│   ...
6364...
65```
66> **注意:** 测试用例根据不同设备形态差异分为通用用例和非通用用例,建议将通用用例存放在common目录下,非通用用例存放在相应设备形态目录下。
67
68####  测试用例编写
69本测试框架支持多种类型测试,针对不同测试类型提供了不同的用例编写模板以供参考。
70
71**TDD测试(C++)**
72
73- 用例源文件命名规范
74
75    测试用例源文件名称和测试套内容保持一致,文件命名采用全小写+下划线方式命名,以test结尾,具体格式为:[功能]_[子功能]_test,子功能支持向下细分。
76示例:
77    ```
78    calculator_sub_test.cpp
79    ```
80
81- 用例示例
82    ```
83    /*
84     * Copyright (c) 2021 XXXX Device Co., Ltd.
85     * Licensed under the Apache License, Version 2.0 (the "License");
86     * you may not use this file except in compliance with the License.
87     * You may obtain a copy of the License at
88     *
89     *     http://www.apache.org/licenses/LICENSE-2.0
90     *
91     * Unless required by applicable law or agreed to in writing, software
92     * distributed under the License is distributed on an "AS IS" BASIS,
93     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
94     * See the License for the specific language governing permissions and
95     * limitations under the License.
96     */
97
98    #include "calculator.h"
99    #include <gtest/gtest.h>
100
101    using namespace testing::ext;
102
103    class CalculatorSubTest : public testing::Test {
104    public:
105        static void SetUpTestCase(void);
106        static void TearDownTestCase(void);
107        void SetUp();
108        void TearDown();
109    };
110
111    void CalculatorSubTest::SetUpTestCase(void)
112    {
113        // input testsuit setup step,setup invoked before all testcases
114    }
115
116    void CalculatorSubTest::TearDownTestCase(void)
117    {
118        // input testsuit teardown step,teardown invoked after all testcases
119    }
120
121    void CalculatorSubTest::SetUp(void)
122    {
123        // input testcase setup step,setup invoked before each testcases
124    }
125
126    void CalculatorSubTest::TearDown(void)
127    {
128        // input testcase teardown step,teardown invoked after each testcases
129    }
130
131    /**
132     * @tc.name: integer_sub_001
133     * @tc.desc: Verify the sub function.
134     * @tc.type: FUNC
135     * @tc.require: issueNumber
136     */
137    HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1)
138    {
139        // step 1:调用函数获取结果
140        int actual = Sub(4,0);
141
142        // Step 2:使用断言比较预期与实际结果
143        EXPECT_EQ(4, actual);
144    }
145    ```
146    详细内容介绍:
147    1. 添加测试用例文件头注释信息
148	    ```
149    	/*
150    	 * Copyright (c) 2021 XXXX Device Co., Ltd.
151    	 * Licensed under the Apache License, Version 2.0 (the "License");
152    	 * you may not use this file except in compliance with the License.
153    	 * You may obtain a copy of the License at
154    	 *
155    	 *     http://www.apache.org/licenses/LICENSE-2.0
156    	 *
157    	 * Unless required by applicable law or agreed to in writing, software
158    	 * distributed under the License is distributed on an "AS IS" BASIS,
159    	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
160    	 * See the License for the specific language governing permissions and
161    	 * limitations under the License.
162    	 */
163    	```
164    2. 引用测试框架头文件和命名空间
165	    ```
166    	#include <gtest/gtest.h>
167
168    	using namespace testing::ext;
169    	```
170    3. 添加被测试类的头文件
171	    ```
172    	#include "calculator.h"
173    	```
174    4. 定义测试套(测试类)
175	    ```
176    	class CalculatorSubTest : public testing::Test {
177    	public:
178    	    static void SetUpTestCase(void);
179    	    static void TearDownTestCase(void);
180    	    void SetUp();
181    	    void TearDown();
182    	};
183
184    	void CalculatorSubTest::SetUpTestCase(void)
185    	{
186    	    // input testsuit setup step,setup invoked before all testcases
187    	}
188
189    	void CalculatorSubTest::TearDownTestCase(void)
190    	{
191    	    // input testsuit teardown step,teardown invoked after all testcases
192    	}
193
194    	void CalculatorSubTest::SetUp(void)
195    	{
196    	    // input testcase setup step,setup invoked before each testcases
197    	}
198
199    	void CalculatorSubTest::TearDown(void)
200    	{
201    	    // input testcase teardown step,teardown invoked after each testcases
202    	}
203    	```
204	    > **注意:** 在定义测试套时,测试套名称应与编译目标保持一致,采用大驼峰风格。
205
206    5. 测试用例实现,包含用例注释和逻辑实现
207	    ```
208    	/**
209    	 * @tc.name: integer_sub_001
210    	 * @tc.desc: Verify the sub function.
211    	 * @tc.type: FUNC
212    	 * @tc.require: issueNumber
213    	 */
214    	HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1)
215    	{
216    	    //step 1:调用函数获取结果
217    	    int actual = Sub(4,0);
218
219    	    //Step 2:使用断言比较预期与实际结果
220    	    EXPECT_EQ(4, actual);
221    	}
222    	```
223		> **注意:** @tc.require: 格式必须以AR/SR或issue开头: 如:issueI56WJ7
224
225	    在编写用例时,我们提供了三种用例模板供您选择。
226
227	    |      类型 |    描述 |
228    	| ------------| ------------|
229    	| HWTEST(A,B,C)| 用例执行不依赖Setup&Teardown时,可选取|
230    	| HWTEST_F(A,B,C)| 用例执行(不含参数)依赖于Setup&Teardown时,可选取|
231    	| HWTEST_P(A,B,C)| 用例执行(含参数)依赖于Set&Teardown时,可选取|
232
233	    其中,参数A,B,C的含义如下:
234	- 参数A为测试套名。
235	- 参数B为测试用例名,其命名必须遵循[功能点]_[编号]的格式,编号为3位数字,从001开始。
236	- 参数C为测试用例等级,具体分为门禁level0 以及非门禁level1-level4共五个等级,其中非门禁level1-level4等级的具体选取规则为:测试用例功能越重要,level等级越低。
237
238	    **注意:**
239	- 测试用例的预期结果必须有对应的断言。
240	- 测试用例必须填写用例等级。
241	- 测试体建议按照模板分步实现。
242	- 用例描述信息按照标准格式@tc.xxx value书写,注释信息必须包含用例名称,用例描述,用例类型,需求编号四项。其中用例测试类型@tc.type参数的选取,可参考下表。
243
244	    | 测试类型名称|类型编码|
245    	| ------------|------------|
246    	|功能测试      |FUNC|
247        |性能测试      |PERF|
248        |可靠性测试    |RELI|
249        |安全测试      |SECU|
250        |模糊测试      |FUZZ|
251
252
253**TDD测试(JS)**
254
255
256- 用例源文件命名规范
257
258    测试用例原文件名称采用大驼峰风格,以TEST结尾,具体格式为:[功能][子功能]TEST,子功能支持向下细分。
259示例:
260    ```
261    AppInfoTest.js
262    ```
263
264- 用例示例
265    ```
266    /*
267     * Copyright (C) 2021 XXXX Device Co., Ltd.
268     * Licensed under the Apache License, Version 2.0 (the "License");
269     * you may not use this file except in compliance with the License.
270     * You may obtain a copy of the License at
271     *
272     *     http://www.apache.org/licenses/LICENSE-2.0
273     *
274     * Unless required by applicable law or agreed to in writing, software
275     * distributed under the License is distributed on an "AS IS" BASIS,
276     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
277     * See the License for the specific language governing permissions and
278     * limitations under the License.
279     */
280    import app from '@system.app'
281
282    import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
283
284    describe("AppInfoTest", function () {
285        beforeAll(function() {
286            // input testsuit setup step,setup invoked before all testcases
287             console.info('beforeAll caled')
288        })
289
290        afterAll(function() {
291             // input testsuit teardown step,teardown invoked after all testcases
292             console.info('afterAll caled')
293        })
294
295        beforeEach(function() {
296            // input testcase setup step,setup invoked before each testcases
297             console.info('beforeEach caled')
298        })
299
300        afterEach(function() {
301            // input testcase teardown step,teardown invoked after each testcases
302             console.info('afterEach caled')
303        })
304
305        /*
306         * @tc.name:appInfoTest001
307         * @tc.desc:verify app info is not null
308         * @tc.type: FUNC
309         * @tc.require: issueNumber
310         */
311        it("appInfoTest001", 0, function () {
312            //step 1:调用函数获取结果
313            var info = app.getInfo()
314
315            //Step 2:使用断言比较预期与实际结果
316            expect(info != null).assertEqual(true)
317        })
318    })
319    ```
320    详细内容介绍:
321    1. 添加测试用例文件头注释信息
322	    ```
323    	/*
324    	 * Copyright (C) 2021 XXXX Device Co., Ltd.
325    	 * Licensed under the Apache License, Version 2.0 (the "License");
326    	 * you may not use this file except in compliance with the License.
327    	 * You may obtain a copy of the License at
328    	 *
329    	 *     http://www.apache.org/licenses/LICENSE-2.0
330    	 *
331    	 * Unless required by applicable law or agreed to in writing, software
332    	 * distributed under the License is distributed on an "AS IS" BASIS,
333    	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
334    	 * See the License for the specific language governing permissions and
335    	 * limitations under the License.
336    	 */
337    	```
338    2. 导入被测api和jsunit测试库
339	    ```
340    	import app from '@system.app'
341
342    	import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
343    	```
344    3. 定义测试套(测试类)
345	    ```
346    	describe("AppInfoTest", function () {
347    	    beforeAll(function() {
348    	        // input testsuit setup step,setup invoked before all testcases
349    	         console.info('beforeAll caled')
350    	    })
351
352    	    afterAll(function() {
353    	         // input testsuit teardown step,teardown invoked after all testcases
354    	         console.info('afterAll caled')
355    	    })
356
357    	    beforeEach(function() {
358    	        // input testcase setup step,setup invoked before each testcases
359    	         console.info('beforeEach caled')
360    	    })
361
362    	    afterEach(function() {
363    	        // input testcase teardown step,teardown invoked after each testcases
364    	         console.info('afterEach caled')
365    	    })
366    	```
367    4. 测试用例实现
368	    ```
369    	/*
370    	 * @tc.name:appInfoTest001
371    	 * @tc.desc:verify app info is not null
372    	 * @tc.type: FUNC
373    	 * @tc.require: issueNumber
374    	 */
375    	 it("appInfoTest001", 0, function () {
376    	    //step 1:调用函数获取结果
377            var info = app.getInfo()
378
379            //Step 2:使用断言比较预期与实际结果
380            expect(info != null).assertEqual(true)
381    	 })
382    	```
383		> **注意:** @tc.require: 格式必须以AR/SR或issue开头: 如:issueI56WJ7
384
385**Fuzz测试**
386
387[Fuzz用例编写规范](https://gitee.com/openharmony/test_developertest/blob/master/libs/fuzzlib/README_zh.md)
388
389
390**Benchmark测试**
391
392[Benchmark用例编写规范](https://gitee.com/openharmony/test_developertest/blob/master/libs/benchmark/README_zh.md)
393
394
395#### 测试用例编译文件编写
396根据测试用例目录规划,当执行某一用例时,测试框架会根据编译文件逐层查找,最终找到所需用例进行编译。下面通过不同示例来讲解gn文件如何编写。
397
398**TDD测试**
399
400针对不同语言,下面提供不同的编译模板以供参考。
401
402- **C++用例编译配置示例**
403
404    ```
405    # Copyright (c) 2021 XXXX Device Co., Ltd.
406
407    import("//build/test.gni")
408
409    module_output_path = "developertest/calculator"
410
411    config("module_private_config") {
412      visibility = [ ":*" ]
413
414      include_dirs = [ "../../../include" ]
415    }
416
417    ohos_unittest("CalculatorSubTest") {
418      module_out_path = module_output_path
419
420      sources = [
421        "../../../include/calculator.h",
422        "../../../src/calculator.cpp",
423      ]
424
425      sources += [ "calculator_sub_test.cpp" ]
426
427      configs = [ ":module_private_config" ]
428
429      deps = [ "//third_party/googletest:gtest_main" ]
430    }
431
432    group("unittest") {
433      testonly = true
434      deps = [":CalculatorSubTest"]
435    }
436    ```
437    详细内容如下:
438
439	1. 添加文件头注释信息
440        ```
441    	# Copyright (c) 2021 XXXX Device Co., Ltd.
442    	```
443	2. 导入编译模板文件
444        ```
445    	import("//build/test.gni")
446    	```
447    3. 指定文件输出路径
448    	```
449    	module_output_path = "developertest/calculator"
450    	```
451    	> **说明:** 此处输出路径为部件/模块名。
452
453    4. 配置依赖包含目录
454
455    	```
456    	config("module_private_config") {
457    	  visibility = [ ":*" ]
458
459    	  include_dirs = [ "../../../include" ]
460    	}
461    	```
462    	> **说明:** 一般在此处对相关配置进行设置,在测试用例编译脚本中可直接引用。
463
464    5. 指定测试用例编译目标输出的文件名称
465
466    	```
467    	ohos_unittest("CalculatorSubTest") {
468    	}
469    	```
470    6. 编写具体的测试用例编译脚本(添加需要参与编译的源文件、配置和依赖)
471    	```
472    	ohos_unittest("CalculatorSubTest") {
473    	  module_out_path = module_output_path
474    	  sources = [
475    	    "../../../include/calculator.h",
476    	    "../../../src/calculator.cpp",
477    	    "../../../test/calculator_sub_test.cpp"
478    	  ]
479    	  sources += [ "calculator_sub_test.cpp" ]
480    	  configs = [ ":module_private_config" ]
481    	  deps = [ "//third_party/googletest:gtest_main" ]
482    	}
483    	```
484
485        > **说明:根据测试类型的不同,在具体编写过程中可选择不同的测试类型:**
486    	> - ohos_unittest:单元测试
487    	> - ohos_moduletest:模块测试
488    	> - ohos_systemtest:系统测试
489    	> - ohos_performancetest:性能测试
490    	> - ohos_securitytest:安全测试
491    	> - ohos_reliabilitytest:可靠性测试
492    	> - ohos_distributedtest:分布式测试
493
494    7. 对目标测试用例文件进行条件分组
495
496    	```
497    	group("unittest") {
498    	  testonly = true
499    	  deps = [":CalculatorSubTest"]
500    	}
501    	```
502    	> **说明:** 进行条件分组的目的在于执行用例时可以选择性的执行某一种特定类型的用例。
503
504- **JavaScript用例编译配置示例**
505
506    ```
507    # Copyright (C) 2021 XXXX Device Co., Ltd.
508
509    import("//build/test.gni")
510
511    module_output_path = "developertest/app_info"
512
513    ohos_js_unittest("GetAppInfoJsTest") {
514      module_out_path = module_output_path
515
516      hap_profile = "./config.json"
517      certificate_profile = "//test/developertest/signature/openharmony_sx.p7b"
518    }
519
520    group("unittest") {
521      testonly = true
522      deps = [ ":GetAppInfoJsTest" ]
523    }
524    ```
525
526    详细内容如下:
527
528    1. 添加文件头注释信息
529
530    	```
531    	# Copyright (C) 2021 XXXX Device Co., Ltd.
532    	```
533    2. 导入编译模板文件
534
535    	```
536    	import("//build/test.gni")
537    	```
538    3. 指定文件输出路径
539
540    	```
541    	module_output_path = "developertest/app_info"
542    	```
543    	> **说明:** 此处输出路径为部件/模块名。
544
545    4. 指定测试用例编译目标输出的文件名称
546
547    	```
548    	ohos_js_unittest("GetAppInfoJsTest") {
549    	}
550    	```
551    	> **说明:**
552    	>- 使用模板ohos_js_unittest定义js测试套,注意与C++用例区分。
553    	>- js测试套编译输出文件为hap类型,hap名为此处定义的测试套名,测试套名称必须以JsTest结尾。
554
555    5. 指定hap包配置文件config.json和签名文件,两个配置为必选项
556
557    	```
558    	ohos_js_unittest("GetAppInfoJsTest") {
559    	  module_out_path = module_output_path
560
561    	  hap_profile = "./config.json"
562    	  certificate_profile = "//test/developertest/signature/openharmony_sx.p7b"
563    	}
564    	```
565    	 config.json为hap编译所需配置文件,需要开发者根据被测sdk版本配置“target”项,其余项可默认,具体如下所示:
566
567    	```
568    	{
569    	  "app": {
570    	    "bundleName": "com.example.myapplication",
571    	    "vendor": "example",
572    	    "version": {
573    	      "code": 1,
574    	      "name": "1.0"
575    	    },
576    	    "apiVersion": {
577    	           "compatible": 4,
578    	         "target": 5     // 根据被测sdk版本进行修改,此例为sdk5
579    	    }
580    	  },
581    	  "deviceConfig": {},
582    	  "module": {
583    	    "package": "com.example.myapplication",
584    	    "name": ".MyApplication",
585    	    "deviceType": [
586    	      "phone"
587    	    ],
588    	    "distro": {
589    	      "deliveryWithInstall": true,
590    	      "moduleName": "entry",
591    	      "moduleType": "entry"
592    	    },
593    	    "abilities": [
594    	      {
595    	      "skills": [
596    	          {
597    	            "entities": [
598    	              "entity.system.home"
599    	            ],
600    	            "actions": [
601    	              "action.system.home"
602    	            ]
603    	          }
604    	        ],
605    	        "name": "com.example.myapplication.MainAbility",
606    	        "icon": "$media:icon",
607    	        "description": "$string:mainability_description",
608    	        "label": "MyApplication",
609    	        "type": "page",
610    	        "launchType": "standard"
611    	      }
612    	    ],
613    	    "js": [
614    	      {
615    	        "pages": [
616    	          "pages/index/index"
617    	        ],
618    	        "name": "default",
619    	          "window": {
620    	             "designWidth": 720,
621    	             "autoDesignWidth": false
622    	          }
623    	        }
624    	      ]
625    	    }
626    	  }
627    	```
628    6. 对目标测试用例文件进行条件分组
629    	```
630    	group("unittest") {
631    	  testonly = true
632    	  deps = [ ":GetAppInfoJsTest" ]
633    	}
634    	```
635    	> **说明:** 进行条件分组的目的在于执行用例时可以选择性的执行某一种特定类型的用例。
636
637**Fuzz测试**
638
639[Fuzz编译文件编写规范](https://gitee.com/openharmony/test_developertest/blob/master/libs/fuzzlib/README_zh.md)
640
641**Benchmark测试**
642
643[Benchmark编译文件编写规范](https://gitee.com/openharmony/test_developertest/blob/master/libs/benchmark/README_zh.md)
644
645
646**编译入口配置文件ohos.build**
647
648当完成用例编译配置文件编写后,需要进一步编写部件编译配置文件,以关联到具体的测试用例。
649```
650"partA": {
651    "module_list": [
652
653    ],
654    "inner_list": [
655
656    ],
657    "system_kits": [
658
659    ],
660    "test_list": [ //配置模块calculator下的test
661      "//system/subsystem/partA/calculator/test:unittest",
662      "//system/subsystem/partA/calculator/test:fuzztest",
663      "//system/subsystem/partA/calculator/test:benchmarktest"
664 }
665```
666> **说明:** test_list中配置的是对应模块的测试用例。
667
668#### 测试用例资源配置
669测试依赖资源主要包括测试用例在执行过程中需要的图片文件,视频文件、第三方库等对外的文件资源。
670
671依赖资源文件配置步骤如下:
6721. 在部件的test目录下创建resource目录,在resource目录下创建对应的模块,在模块目录中存放该模块所需要的资源文件
673
6742. 在resource目录下对应的模块目录中创建一个ohos_test.xml文件,文件内容格式如下:
675	```
676	<?xml version="1.0" encoding="UTF-8"?>
677	<configuration ver="2.0">
678	    <target name="CalculatorSubTest">
679	        <preparer>
680	            <option name="push" value="test.jpg -> /data/test/resource" src="res"/>
681	            <option name="push" value="libc++.z.so -> /data/test/resource" src="out"/>
682	        </preparer>
683	    </target>
684	</configuration>
685	```
6863. 在测试用例的编译配置文件中定义resource_config_file进行指引,用来指定对应的资源文件ohos_test.xml
687	```
688	ohos_unittest("CalculatorSubTest") {
689	  resource_config_file = "//system/subsystem/partA/test/resource/calculator/ohos_test.xml"
690	}
691	```
692	>**说明:**
693	>- target_name: 测试套的名称,定义在测试目录的BUILD.gn中。preparer: 表示该测试套执行前执行的动作。
694	>- src="res": 表示测试资源位于test目录下的resource目录下,src="out":表示位于out/release/$(部件)目录下。
695
696### 测试用例执行
697在执行测试用例之前,针对用例使用设备的不同,需要对相应配置进行修改,修改完成即可执行测试用例。
698
699#### user_config.xml配置
700```
701<user_config>
702  <build>
703    <!-- 是否编译demo用例, 默认为false,如果需要编译demo可修改为true -->
704    <example>false</example>
705    <!-- 是否编译版本, 默认为false -->
706    <version>false</version>
707    <!-- 是否编译测试用例, 默认为true,若已完成编译,再执行用例之前可修改为false,防止重新编译 -->
708    <testcase>true</testcase>
709	<!-- 在编译测试用例的情况下,选择编译target_cpu是64位的还是32位的,默认为空(32bit)可以选择: arm64 -->
710    <parameter>
711       <target_cpu></target_cpu>
712    </parameter>
713  </build>
714  <environment>
715    <!-- 配置远程映射机器的IP及端口,以支持HDC连接的设备 -->
716    <device type="usb-hdc">
717      <ip></ip>
718      <port></port>
719      <sn></sn>
720    </device>
721    <!-- 配置设备的串口信息,以支持串口连接的设备 -->
722    <device type="com" label="ipcamera">
723      <serial>
724        <com></com>
725        <type>cmd</type>
726        <baud_rate>115200</baud_rate>
727        <data_bits>8</data_bits>
728        <stop_bits>1</stop_bits>
729        <timeout>1</timeout>
730      </serial>
731    </device>
732  </environment>
733  <!-- 配置测试用例路径,若测试用例未编译,即<testcase>标签属性为true时,此处默认不填写;若编译已完成,需在此处指定测试用例的实际路径 -->
734  <test_cases>
735    <dir></dir>
736  </test_cases>
737  <!-- 配置覆盖率编译路径 -->
738  <coverage>
739    <outpath></outpath>
740  </coverage>
741  <!-- NFS挂载信息配置,被测设备仅支持串口连接时配置,指定NFS的映射路径,host_dir为PC侧的NFS目录,board_dir为板侧创建的目录 -->
742  <NFS>
743    <host_dir></host_dir>
744    <mnt_cmd></mnt_cmd>
745    <board_dir></board_dir>
746  </NFS>
747</user_config>
748```
749>**说明:** 在执行测试用例之前,若使用HDC连接设备,用例仅需配置设备IP和端口号即可,其余信息均默认不修改。
750
751#### Windows环境执行
752##### 测试用例编译
753
754由于Windows环境下无法实现用例编译,因此执行用例前需要在Linux环境下进行用例编译,用例编译命令:
755```
756./build.sh --product-name {product_name} --build-target make_test
757```
758>说明:
759> - product-name:指定编译产品名称。
760> - build-target:指定所需编译用例,make_test表示指定全部用例,实际开发中可指定特定用例。
761
762编译完成后,测试用例将自动保存在out/ohos-arm-release/packages/phone/tests目录下。
763
764##### 搭建执行环境
7651. 在Windows环境创建测试框架目录Test,并在此目录下创建testcase目录
766
7672. 从Linux环境拷贝测试框架developertest和xdevice到创建的Test目录下,拷贝编译好的测试用例到testcase目录下
768
769	>**说明:** 将测试框架及测试用例从Linux环境移植到Windows环境,以便后续执行。
770
7713. 修改user_config.xml
772	```
773	<build>
774	  <!-- 由于测试用例已编译完成,此标签属性需改为false -->
775	  <testcase>false</testcase>
776	</build>
777	<test_cases>
778	  <!-- 由于已将测试用例拷贝到Windows环境下,测试用例输出路径发生改变,需要修改为拷贝后所存放的路径 -->
779	  <dir>D:\Test\testcase\tests</dir>
780	</test_cases>
781	```
782	>**说明:** `<testcase>`标签表示是否需要编译用例;`<dir>`标签表示测试用例查找路径。
783
784##### 执行用例
7851. 启动测试框架
786	```
787	start.bat
788	```
7892. 选择产品形态
790
791    进入测试框架,系统会自动提示您选择产品形态,请根据实际的开发板进行选择。
792
793	如需手动添加,请在config/framework_config.xml的\<productform\>标签内增加产品项。
794
7953. 执行测试用例
796
797    当选择完产品形态,可参考如下指令执行测试用例。
798	```
799	run -t UT -ts CalculatorSubTest -tc interger_sub_00l
800	```
801	执行命令参数说明:
802	```
803	-t [TESTTYPE]: 指定测试用例类型,有UT,MST,ST,PERF,FUZZ,BENCHMARK等。(必选参数)
804	-tp [TESTPART]: 指定部件,可独立使用。
805	-tm [TESTMODULE]: 指定模块,不可独立使用,需结合-tp指定上级部件使用。
806	-ts [TESTSUITE]: 指定测试套,可独立使用。
807	-tc [TESTCASE]: 指定测试用例,不可独立使用,需结合-ts指定上级测试套使用。
808	-h : 帮助命令。
809	```
810#### Linux环境执行
811##### 远程端口映射
812为了在Linux远程服务器以及Linux虚拟机两种环境下执行测试用例,需要对端口进行远程映射,以实现与设备的数据通路连接。具体操作如下:
8131. HDC Server指令:
814	```
815	hdc_std kill
816	hdc_std -m -s 0.0.0.0:8710
817	```
818	>**说明:** IP和端口号为默认值。
819
8202. HDC Client指令:
821	```
822	hdc_std -s xx.xx.xx.xx:8710 list targets
823	```
824	>**说明:** 此处IP填写设备侧IP地址。
825
826##### 执行用例
8271. 启动测试框架
828	```
829	./start.sh
830	```
8312. 选择产品形态
832
833    进入测试框架,系统会自动提示您选择产品形态,请根据实际的开发板进行选择。
834
835	如需手动添加,请在config/framework_config.xml的\<productform\>标签内增加产品项。
836
8373. 执行测试用例
838
839    测试框架在执行用例时会根据指令找到所需用例,自动实现用例编译,执行过程,完成自动化测试。
840	```
841	run -t UT -ts CalculatorSubTest -tc interger_sub_00l
842	```
843	执行命令参数说明:
844	```
845	-t [TESTTYPE]: 指定测试用例类型,有UT,MST,ST,PERF,FUZZ,BENCHMARK等。(必选参数)
846	-tp [TESTPART]: 指定部件,可独立使用。
847	-tm [TESTMODULE]: 指定模块,不可独立使用,需结合-tp指定上级部件使用。
848	-ts [TESTSUITE]: 指定测试套,可独立使用。
849	-tc [TESTCASE]: 指定测试用例,不可独立使用,需结合-ts指定上级测试套使用。
850	-h : 帮助命令。
851	```
852
853### 测试报告日志
854当执行完测试指令,控制台会自动生成测试结果,若需要详细测试报告您可在相应的数据文档中进行查找。
855
856#### 测试结果
857测试结果输出根路径如下:
858```
859test/developertest/reports/xxxx_xx_xx_xx_xx_xx
860```
861>**说明:** 测试报告文件目录将自动生成。
862
863该目录中包含以下几类结果:
864| 类型 | 描述|
865| ------------ | ------------ |
866| result/ |测试用例格式化结果|
867| log/plan_log_xxxx_xx_xx_xx_xx_xx.log | 测试用例日志 |
868| summary_report.html | 测试报告汇总 |
869| details_report.html | 测试报告详情 |
870
871#### 测试框架日志
872```
873reports/platform_log_xxxx_xx_xx_xx_xx_xx.log
874```
875
876#### 最新测试报告
877```
878reports/latest
879```
880
881### 涉及仓
882
883[test\_xdevice](https://gitee.com/openharmony/test_xdevice/blob/master/README_zh.md)
884
885## 发布版本说明
886
887| 发布版本号 | 发布功能说明                                                 |
888| ---------- | ------------------------------------------------------------ |
889| 3.2.1.0    | 1、增加框架对接执行ACTS测试用例能力<br />2、增加ACTS多种颗粒度执行能力,如子系统、部件等 |
890| 3.2.2.0    | 1、增加测试任务统计能力,最多统计10个任务<br />2、增加按照指定测试任务ID执行测试任务能力<br />3、增加复测上次任务失败用例能力 |
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910