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