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