• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 测试子系统
2OpenHarmony为开发者提供了一套全面的自测试框架,开发者可根据测试需求开发相关测试用例,开发阶段提前发现缺陷,大幅提高代码质量。
3
4本文从基础环境构建,用例开发,编译以及执行等方面介绍OpenHarmony测试框架如何运行和使用。
5## 基础环境构建
6测试框架依赖于python运行环境,在使用测试框架之前可参阅以下方式进行配置。
7 - [环境配置](../device-dev/subsystems/subsys-testguide-envbuild.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    ```
231    import app from '@system.app'
232
233    import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
234
235    describe("AppInfoTest", function () {
236        beforeAll(function() {
237            // input testsuit setup step,setup invoked before all testcases
238             console.info('beforeAll caled')
239        })
240
241        afterAll(function() {
242             // input testsuit teardown step,teardown invoked after all testcases
243             console.info('afterAll caled')
244        })
245
246        beforeEach(function() {
247            // input testcase setup step,setup invoked before each testcases
248             console.info('beforeEach caled')
249        })
250
251        afterEach(function() {
252            // input testcase teardown step,teardown invoked after each testcases
253             console.info('afterEach caled')
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, function () {
263            //step 1:调用函数获取结果
264            var info = app.getInfo()
265
266            //Step 2:使用断言比较预期与实际结果
267            expect(info != null).assertEqual(true)
268        })
269    })
270    ```
271    详细内容介绍:
272    1. 添加测试用例文件头注释信息
273
274        按照标准头注释信息格式填写,请查阅[编写规范](https://gitee.com/openharmony/docs/blob/master/zh-cn/contribute/%E8%B4%A1%E7%8C%AE%E4%BB%A3%E7%A0%81.md)275
276    2. 导入被测api和jsunit测试库
277	    ```
278    	import app from '@system.app'
279
280    	import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
281    	```
282    3. 定义测试套(测试类)
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    4. 测试用例实现
306	    ```
307    	/*
308    	 * @tc.name:appInfoTest001
309    	 * @tc.desc:verify app info is not null
310    	 * @tc.type: FUNC
311    	 * @tc.require: Issue Number
312    	 */
313    	 it("appInfoTest001", 0, function () {
314    	    //step 1:调用函数获取结果
315            var info = app.getInfo()
316
317            //Step 2:使用断言比较预期与实际结果
318            expect(info != null).assertEqual(true)
319    	 })
320    	```
321
322### 测试用例编译文件编写
323根据测试用例目录规划,当执行某一用例时,测试框架会根据编译文件逐层查找,最终找到所需用例进行编译。下面通过不同示例来讲解gn文件如何编写。
324
325#### 测试用例编译配置文件
326针对不同语言,下面提供不同的编译模板以供参考。
327
328- **C++用例编译配置示例**
329    ```
330
331    import("//build/test.gni")
332
333    module_output_path = "subsystem_examples/calculator"
334
335    config("module_private_config") {
336      visibility = [ ":*" ]
337
338      include_dirs = [ "../../../include" ]
339    }
340
341    ohos_unittest("CalculatorSubTest") {
342      module_out_path = module_output_path
343
344      sources = [
345        "../../../include/calculator.h",
346        "../../../src/calculator.cpp",
347      ]
348
349      sources += [ "calculator_sub_test.cpp" ]
350
351      configs = [ ":module_private_config" ]
352
353      deps = [ "//third_party/googletest:gtest_main" ]
354    }
355
356    group("unittest") {
357      testonly = true
358      deps = [":CalculatorSubTest"]
359    }
360    ```
361    详细内容如下:
362
363    1. 添加文件头注释信息
364
365        按照标准头注释信息格式填写,请查阅[编写规范](https://gitee.com/openharmony/docs/blob/master/zh-cn/contribute/%E8%B4%A1%E7%8C%AE%E4%BB%A3%E7%A0%81.md)366
367    2. 导入编译模板文件
368	    ```
369    	import("//build/test.gni")
370    	```
371    3. 指定文件输出路径
372    	```
373    	module_output_path = "subsystem_examples/calculator"
374    	```
375    	> **说明:** 此处输出路径为部件/模块名。
376
377    4. 配置依赖包含目录
378
379    	```
380    	config("module_private_config") {
381    	  visibility = [ ":*" ]
382
383    	  include_dirs = [ "../../../include" ]
384    	}
385    	```
386    	> **说明:** 一般在此处对相关配置进行设置,在测试用例编译脚本中可直接引用。
387
388    5. 指定测试用例编译目标输出的文件名称
389
390    	```
391    	ohos_unittest("CalculatorSubTest") {
392    	}
393    	```
394    6. 编写具体的测试用例编译脚本(添加需要参与编译的源文件、配置和依赖)
395    	```
396    	ohos_unittest("CalculatorSubTest") {
397    	  module_out_path = module_output_path
398    	  sources = [
399    	    "../../../include/calculator.h",
400    	    "../../../src/calculator.cpp",
401    	    "../../../test/calculator_sub_test.cpp"
402    	  ]
403    	  sources += [ "calculator_sub_test.cpp" ]
404    	  configs = [ ":module_private_config" ]
405    	  deps = [ "//third_party/googletest:gtest_main" ]
406    	}
407    	```
408
409	    > **说明:根据测试类型的不同,在具体编写过程中可选择不同的测试类型:**
410    	> - ohos_unittest:单元测试
411    	> - ohos_moduletest:模块测试
412    	> - ohos_systemtest:系统测试
413    	> - ohos_performancetest:性能测试
414    	> - ohos_securitytest:安全测试
415    	> - ohos_reliabilitytest:可靠性测试
416    	> - ohos_distributedtest:分布式测试
417
418    7. 对目标测试用例文件进行条件分组
419
420    	```
421    	group("unittest") {
422    	  testonly = true
423    	  deps = [":CalculatorSubTest"]
424    	}
425    	```
426    	> **说明:** 进行条件分组的目的在于执行用例时可以选择性的执行某一种特定类型的用例。
427
428- **JavaScript用例编译配置示例**
429
430    ```
431
432    import("//build/test.gni")
433
434    module_output_path = "subsystem_examples/app_info"
435
436    ohos_js_unittest("GetAppInfoJsTest") {
437      module_out_path = module_output_path
438
439      hap_profile = "./config.json"
440      certificate_profile = "//test/developertest/signature/openharmony_sx.p7b"
441    }
442
443    group("unittest") {
444      testonly = true
445      deps = [ ":GetAppInfoJsTest" ]
446    }
447    ```
448
449    详细内容如下:
450
451    1. 添加文件头注释信息
452
453        按照标准头注释信息格式填写,请查阅[编写规范](https://gitee.com/openharmony/docs/blob/master/zh-cn/contribute/%E8%B4%A1%E7%8C%AE%E4%BB%A3%E7%A0%81.md)454
455    2. 导入编译模板文件
456
457    	```
458    	import("//build/test.gni")
459    	```
460    3. 指定文件输出路径
461
462    	```
463    	module_output_path = "subsystem_examples/app_info"
464    	```
465    	> **说明:** 此处输出路径为部件/模块名。
466
467    4. 指定测试用例编译目标输出的文件名称
468
469    	```
470    	ohos_js_unittest("GetAppInfoJsTest") {
471    	}
472    	```
473    	> **说明:**
474    	>- 使用模板ohos_js_unittest定义js测试套,注意与C++用例区分。
475    	>- js测试套编译输出文件为hap类型,hap名为此处定义的测试套名,测试套名称必须以JsTest结尾。
476
477    5. 指定hap包配置文件config.json和签名文件,两个配置为必选项
478
479    	```
480    	ohos_js_unittest("GetAppInfoJsTest") {
481    	  module_out_path = module_output_path
482
483    	  hap_profile = "./config.json"
484    	  certificate_profile = "//test/developertest/signature/openharmony_sx.p7b"
485    	}
486    	```
487    	 config.json为hap编译所需配置文件,需要开发者根据被测sdk版本配置“target”项,其余项可默认,具体如下所示:
488
489    	```
490    	{
491    	  "app": {
492    	    "bundleName": "com.example.myapplication",
493    	    "vendor": "example",
494    	    "version": {
495    	      "code": 1,
496    	      "name": "1.0"
497    	    },
498    	    "apiVersion": {
499    	           "compatible": 4,
500    	         "target": 5     // 根据被测sdk版本进行修改,此例为sdk5
501    	    }
502    	  },
503    	  "deviceConfig": {},
504    	  "module": {
505    	    "package": "com.example.myapplication",
506    	    "name": ".MyApplication",
507    	    "deviceType": [
508    	      "phone"
509    	    ],
510    	    "distro": {
511    	      "deliveryWithInstall": true,
512    	      "moduleName": "entry",
513    	      "moduleType": "entry"
514    	    },
515    	    "abilities": [
516    	      {
517    	      "skills": [
518    	          {
519    	            "entities": [
520    	              "entity.system.home"
521    	            ],
522    	            "actions": [
523    	              "action.system.home"
524    	            ]
525    	          }
526    	        ],
527    	        "name": "com.example.myapplication.MainAbility",
528    	        "icon": "$media:icon",
529    	        "description": "$string:mainability_description",
530    	        "label": "MyApplication",
531    	        "type": "page",
532    	        "launchType": "standard"
533    	      }
534    	    ],
535    	    "js": [
536    	      {
537    	        "pages": [
538    	          "pages/index/index"
539    	        ],
540    	        "name": "default",
541    	          "window": {
542    	             "designWidth": 720,
543    	             "autoDesignWidth": false
544    	          }
545    	        }
546    	      ]
547    	    }
548    	  }
549    	```
550    6. 对目标测试用例文件进行条件分组
551    	```
552    	group("unittest") {
553    	  testonly = true
554    	  deps = [ ":GetAppInfoJsTest" ]
555    	}
556    	```
557    	> **说明:** 进行条件分组的目的在于执行用例时可以选择性的执行某一种特定类型的用例。
558
559#### 编译入口配置文件ohos.build
560
561当完成用例编译配置文件编写后,需要进一步编写部件编译配置文件,以关联到具体的测试用例。
562```
563"partA": {
564    "module_list": [
565
566    ],
567    "inner_list": [
568
569    ],
570    "system_kits": [
571
572    ],
573    "test_list": [
574      "//system/subsystem/partA/calculator/test:unittest"  //配置模块calculator下的test
575    ]
576 }
577```
578> **说明:** test_list中配置的是对应模块的测试用例。
579
580### 测试用例资源配置
581测试依赖资源主要包括测试用例在执行过程中需要的图片文件,视频文件、第三方库等对外的文件资源。
582
583依赖资源文件配置步骤如下:
5841. 在部件的test目录下创建resource目录,在resource目录下创建对应的模块,在模块目录中存放该模块所需要的资源文件
585
5862. 在resource目录下对应的模块目录中创建一个ohos_test.xml文件,文件内容格式如下:
587	```
588	<?xml version="1.0" encoding="UTF-8"?>
589	<configuration ver="2.0">
590	    <target name="CalculatorSubTest">
591	        <preparer>
592	            <option name="push" value="test.jpg -> /data/test/resource" src="res"/>
593	            <option name="push" value="libc++.z.so -> /data/test/resource" src="out"/>
594	        </preparer>
595	    </target>
596	</configuration>
597	```
5983. 在测试用例的编译配置文件中定义resource_config_file进行指引,用来指定对应的资源文件ohos_test.xml
599	```
600	ohos_unittest("CalculatorSubTest") {
601	  resource_config_file = "//system/subsystem/partA/test/resource/calculator/ohos_test.xml"
602	}
603	```
604	>**说明:**
605	>- target_name: 测试套的名称,定义在测试目录的BUILD.gn中。preparer: 表示该测试套执行前执行的动作。
606	>- src="res": 表示测试资源位于test目录下的resource目录下,src="out":表示位于out/release/$(部件)目录下。
607
608## 测试用例执行
609在执行测试用例之前,针对用例使用设备的不同,需要对相应配置进行修改,修改完成即可执行测试用例。
610
611### user_config.xml配置
612```
613<user_config>
614  <build>
615    <!-- 是否编译demo用例, 默认为false,如果需要编译demo可修改为true -->
616    <example>false</example>
617    <!-- 是否编译版本, 默认为false -->
618    <version>false</version>
619    <!-- 是否编译测试用例, 默认为true,若已完成编译,再执行用例之前可修改为false,防止重新编译 -->
620    <testcase>true</testcase>
621  </build>
622  <environment>
623    <!-- 配置远程映射机器的IP及端口,以支持HDC连接的设备 -->
624    <device type="usb-hdc">
625      <ip></ip>
626      <port></port>
627      <sn></sn>
628    </device>
629    <!-- 配置设备的串口信息,以支持串口连接的设备 -->
630    <device type="com" label="ipcamera">
631      <serial>
632        <com></com>
633        <type>cmd</type>
634        <baud_rate>115200</baud_rate>
635        <data_bits>8</data_bits>
636        <stop_bits>1</stop_bits>
637        <timeout>1</timeout>
638      </serial>
639    </device>
640  </environment>
641  <!-- 配置测试用例路径,若测试用例未编译,即<testcase>标签属性为true时,此处默认不填写;若编译已完成,需在此处指定测试用例的实际路径 -->
642  <test_cases>
643    <dir></dir>
644  </test_cases>
645  <!-- 配置覆盖率编译路径 -->
646  <coverage>
647    <outpath></outpath>
648  </coverage>
649  <!-- NFS挂载信息配置,被测设备仅支持串口连接时配置,指定NFS的映射路径,host_dir为PC侧的NFS目录,board_dir为板侧创建的目录 -->
650  <NFS>
651    <host_dir></host_dir>
652    <mnt_cmd></mnt_cmd>
653    <board_dir></board_dir>
654  </NFS>
655</user_config>
656```
657>**说明:** 在执行测试用例之前,若使用HDC连接设备,用例仅需配置设备IP和端口号即可,其余信息均默认不修改。
658
659### Windows环境执行
660#### 测试用例编译
661
662由于Windows环境下无法实现用例编译,因此执行用例前需要在Linux环境下进行用例编译,用例编译命令:
663```
664./build.sh --product-name Hi3516DV300 --build-target make_test
665```
666编译完成后,测试用例将自动保存在out/hi3516dv300/packages/phone/images/tests目录下。
667
668>说明: Hi3516DV300为当前版本所支持的平台,make_test表示全部用例。根据不同需求,编译选项可进行不同选择:
669> -  --product-name   # 编译产品名称(必选)
670> - --build-target   # 指定编译目标(可选)
671
672#### 搭建执行环境
6731. 在Windows环境创建测试框架目录Test,并在此目录下创建testcase目录
674
6752. 从Linux环境拷贝测试框架developertest和xdevice到创建的Test目录下,拷贝编译好的测试用例到testcase目录下
676
677>**说明:** 将测试框架及测试用例从Linux环境移植到Windows环境,以便后续执行。
678
6793. 修改user_config.xml
680	```
681	<build>
682	  <!-- 由于测试用例已编译完成,此标签属性需改为false -->
683	  <testcase>false</testcase>
684	</build>
685	<test_cases>
686	  <!-- 由于已将测试用例拷贝到Windows环境下,测试用例输出路径发生改变,需要修改为拷贝后所存放的路径 -->
687	  <dir>D:\Test\testcase\tests</dir>
688	</test_cases>
689	```
690	>**说明:** `<testcase>`标签表示是否需要编译用例;`<dir>`标签表示测试用例查找路径。
691
692#### 执行用例
6931. 启动测试框架
694	```
695	start.bat
696	```
6972. 选择产品形态
698
699    进入测试框架,系统会自动提示您选择产品形态,请根据实际的开发板进行选择。例如:Hi3516DV300。
700
7013. 执行测试用例
702
703    当选择完产品形态,可参考如下指令执行测试用例。
704	```
705	run -t UT -ts CalculatorSubTest -tc interger_sub_00l
706	```
707	执行命令参数说明:
708	```
709	-t [TESTTYPE]: 指定测试用例类型,有UT,MST,ST,PERF等。(必选参数)
710	-tp [TESTPART]: 指定部件,可独立使用。
711	-tm [TESTMODULE]: 指定模块,不可独立使用,需结合-tp指定上级部件使用。
712	-ts [TESTSUITE]: 指定测试套,可独立使用。
713	-tc [TESTCASE]: 指定测试用例,不可独立使用,需结合-ts指定上级测试套使用。
714	-h : 帮助命令。
715	```
716### Linux环境执行
717#### 远程端口映射
718为了在Linux远程服务器以及Linux虚拟机两种环境下执行测试用例,需要对端口进行远程映射,以实现与设备的数据通路连接。具体操作如下:
7191. HDC Server指令:
720	```
721	hdc_std kill
722	hdc_std -m -s 0.0.0.0:8710
723	```
724	>**说明:** IP和端口号为默认值。
725
7262. HDC Client指令:
727	```
728	hdc_std -s xx.xx.xx.xx:8710 list targets
729	```
730	>**说明:** 此处IP填写设备侧IP地址。
731
732#### 执行用例
7331. 启动测试框架
734	```
735	./start.sh
736	```
7372. 选择产品形态
738
739    进入测试框架,系统会自动提示您选择产品形态,请根据实际的开发板进行选择。例如:Hi3516DV300。
740
7413. 执行测试用例
742
743    测试框架在执行用例时会根据指令找到所需用例,自动实现用例编译,执行过程,完成自动化测试。
744	```
745	run -t UT -ts CalculatorSubTest -tc interger_sub_00l
746	```
747	执行命令参数说明:
748	```
749	-t [TESTTYPE]: 指定测试用例类型,有UT,MST,ST,PERF等。(必选参数)
750	-tp [TESTPART]: 指定部件,可独立使用。
751	-tm [TESTMODULE]: 指定模块,不可独立使用,需结合-tp指定上级部件使用。
752	-ts [TESTSUITE]: 指定测试套,可独立使用。
753	-tc [TESTCASE]: 指定测试用例,不可独立使用,需结合-ts指定上级测试套使用。
754	-h : 帮助命令。
755	```
756
757## 测试报告日志
758当执行完测试指令,控制台会自动生成测试结果,若需要详细测试报告您可在相应的数据文档中进行查找。
759
760### 测试结果
761测试结果输出根路径如下:
762```
763test/developertest/reports/xxxx_xx_xx_xx_xx_xx
764```
765>**说明:** 测试报告文件目录将自动生成。
766
767该目录中包含以下几类结果:
768| 类型 | 描述|
769| ------------ | ------------ |
770| result/ |测试用例格式化结果|
771| log/plan_log_xxxx_xx_xx_xx_xx_xx.log | 测试用例日志 |
772| summary_report.html | 测试报告汇总 |
773| details_report.html | 测试报告详情 |
774
775### 测试框架日志
776```
777reports/platform_log_xxxx_xx_xx_xx_xx_xx.log
778```
779
780### 最新测试报告
781```
782reports/latest
783```
784
785## 涉及仓
786
787[test\_xdevice](https://gitee.com/openharmony/test_xdevice/blob/master/README_zh.md)
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816