# XTSå系统<a name="ZH-CN_TOPIC_0000001117409671"></a> - [简介](#section465982318513) - [系统类型](#section125090457443) - [目录](#section161941989596) - [约æŸ](#section119744591305) - [使用说明](#section137768191623) - [用例开å‘指导](#section3695134065513) - [Cè¯è¨€ç”¨ä¾‹å¼€å‘编译指导(适用于轻é‡ç³»ç»Ÿäº§å“用例开å‘)](#section198193336544) - [Cè¯è¨€ç”¨ä¾‹æ‰§è¡ŒæŒ‡å¯¼ï¼ˆé€‚用于轻é‡ç³»ç»Ÿäº§å“用例开å‘)](#section13820233175418) - [C++è¯è¨€ç”¨ä¾‹å¼€å‘编译指导(适用于å°åž‹ç³»ç»Ÿã€æ ‡å‡†ç³»ç»Ÿç”¨ä¾‹å¼€å‘)](#section3822123311540) - [C++è¯è¨€ç”¨ä¾‹æ‰§è¡ŒæŒ‡å¯¼ï¼ˆé€‚用于å°åž‹ç³»ç»Ÿã€æ ‡å‡†ç³»ç»Ÿç”¨ä¾‹å¼€å‘)](#section128222336544) - [JSè¯è¨€ç”¨ä¾‹å¼€å‘æŒ‡å¯¼ï¼ˆé€‚ç”¨äºŽæ ‡å‡†ç³»ç»Ÿï¼‰](#section159801435165220) - [JSè¯è¨€ç”¨ä¾‹ç¼–è¯‘æ‰“åŒ…æŒ‡å¯¼ï¼ˆé€‚ç”¨äºŽæ ‡å‡†ç³»ç»Ÿï¼‰](#section445519106559) - [相关仓](#section1371113476307) ## 简介<a name="section465982318513"></a> XTSå系统是OpenHarmony生æ€è®¤è¯æµ‹è¯•å¥—件的集åˆï¼Œå½“å‰åŒ…括acts(application compatibility test suite)应用兼容性测试套件,åŽç»ä¼šæ‹“展dcts(device compatibility test suite)设备兼容性测试套件ç‰ã€‚ XTSå系统当å‰åŒ…括acts与tools软件包: - acts,å˜æ”¾acts相关测试用例æºç 与é…置文件,其目的是帮助终端设备厂商尽早å‘现软件与OpenHarmonyçš„ä¸å…¼å®¹æ€§ï¼Œç¡®ä¿è½¯ä»¶åœ¨æ•´ä¸ªå¼€å‘过程ä¸æ»¡è¶³OpenHarmony的兼容性è¦æ±‚。 - tools,å˜æ”¾acts相关测试用例开å‘框架。 ## 系统类型<a name="section125090457443"></a> OpenHarmony支æŒå¦‚ä¸‹å‡ ç§ç³»ç»Ÿç±»åž‹ï¼š - è½»é‡ç³»ç»Ÿï¼ˆmini system) é¢å‘MCU类处ç†å™¨ä¾‹å¦‚Arm Cortex-Mã€RISC-V 32ä½çš„设备,硬件资æºæžå…¶æœ‰é™ï¼Œæ”¯æŒçš„设备最å°å†…å˜ä¸º128KiB,å¯ä»¥æ供多ç§è½»é‡çº§ç½‘络å议,轻é‡çº§çš„图形框架,以åŠä¸°å¯Œçš„IOT总线读写部件ç‰ã€‚å¯æ”¯æ’‘的产å“如智能家居领域的连接类模组ã€ä¼ 感器设备ã€ç©¿æˆ´ç±»è®¾å¤‡ç‰ã€‚ - å°åž‹ç³»ç»Ÿï¼ˆsmall system) é¢å‘应用处ç†å™¨ä¾‹å¦‚Arm Cortex-A的设备,支æŒçš„设备最å°å†…å˜ä¸º1MiB,å¯ä»¥æ供更高的安全能力ã€æ ‡å‡†çš„图形框架ã€è§†é¢‘编解ç 的多媒体能力。å¯æ”¯æ’‘的产å“如智能家居领域的IP Cameraã€ç”µå猫眼ã€è·¯ç”±å™¨ä»¥åŠæ™ºæ…§å‡ºè¡Œé¢†åŸŸçš„行车记录仪ç‰ã€‚ - æ ‡å‡†ç³»ç»Ÿï¼ˆstandard system) é¢å‘应用处ç†å™¨ä¾‹å¦‚Arm Cortex-A的设备,支æŒçš„设备最å°å†…å˜ä¸º128MiB,å¯ä»¥æ供增强的交互能力ã€3D GPU以åŠç¡¬ä»¶åˆæˆèƒ½åŠ›ã€æ›´å¤šæŽ§ä»¶ä»¥åŠåŠ¨ç”»æ•ˆæžœæ›´ä¸°å¯Œçš„图形能力ã€å®Œæ•´çš„应用框架。å¯æ”¯æ’‘的产å“如高端的冰箱显示å±ã€‚ ## 目录<a name="section161941989596"></a> ``` /test/xts ├── acts # 测试代ç å˜æ”¾ç›®å½• │ └── subsystem # æ ‡å‡†ç³»ç»Ÿå系统测试用例æºç å˜æ”¾ç›®å½• │ └── subsystem_lite # è½»é‡ç³»ç»Ÿã€å°åž‹ç³»ç»Ÿå系统测试用例æºç å˜æ”¾ç›®å½• │ └── BUILD.gn # æ ‡å‡†ç³»ç»Ÿæµ‹è¯•ç”¨ä¾‹ç¼–è¯‘é…ç½® │ └── build_lite # è½»é‡ç³»ç»Ÿã€å°åž‹ç³»ç»Ÿæµ‹è¯•ç”¨ä¾‹ç¼–译é…ç½®å˜æ”¾ç›®å½• │ └── BUILD.gn # è½»é‡ç³»ç»Ÿã€å°åž‹ç³»ç»Ÿæµ‹è¯•ç”¨ä¾‹ç¼–译é…ç½® └── tools # 测试工具代ç å˜æ”¾ç›®å½• ``` ## 约æŸ<a name="section119744591305"></a> è½»é‡ç³»ç»Ÿç”¨ä¾‹å¼€å‘è¯è¨€æ˜¯C,å°åž‹ç³»ç»Ÿç”¨ä¾‹å¼€å‘è¯è¨€æ˜¯C++。 ## 使用说明<a name="section137768191623"></a> **表 1** 用例级别说明 <a name="table12856113719456"></a> <table><thead align="left"><tr id="row88561737114517"><th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.2.4.1.1"><p id="p54711456452"><a name="p54711456452"></a><a name="p54711456452"></a>级别å称</p> </th> <th class="cellrowborder" valign="top" width="33.283328332833285%" id="mcps1.2.4.1.2"><p id="p114834544518"><a name="p114834544518"></a><a name="p114834544518"></a>基本定义</p> </th> <th class="cellrowborder" valign="top" width="33.383338333833386%" id="mcps1.2.4.1.3"><p id="p348154574518"><a name="p348154574518"></a><a name="p348154574518"></a>测试范围</p> </th> </tr> </thead> <tbody><tr id="row78561137134514"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p17481345124512"><a name="p17481345124512"></a><a name="p17481345124512"></a>Level0</p> </td> <td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p1548945204514"><a name="p1548945204514"></a><a name="p1548945204514"></a>冒烟</p> </td> <td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p174824517456"><a name="p174824517456"></a><a name="p174824517456"></a>验è¯å…³é”®åŠŸèƒ½ç‚¹åŸºæœ¬åŠŸèƒ½/最基本DFX属性在最常è§è¾“入下的表现,通过表示功能基本å¯è¿è¡Œã€‚</p> </td> </tr> <tr id="row28563372451"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p448445144512"><a name="p448445144512"></a><a name="p448445144512"></a>Level1</p> </td> <td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p44813452452"><a name="p44813452452"></a><a name="p44813452452"></a>基本</p> </td> <td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p648184584514"><a name="p648184584514"></a><a name="p648184584514"></a>验è¯å„功能点基本功能/基本DFX属性在常è§è¾“入下的表现,通过表示功能基本å¯æµ‹è¯•ã€‚</p> </td> </tr> <tr id="row12856137204514"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p164834520453"><a name="p164834520453"></a><a name="p164834520453"></a>Level2</p> </td> <td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p148245184511"><a name="p148245184511"></a><a name="p148245184511"></a>é‡è¦</p> </td> <td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p348945124510"><a name="p348945124510"></a><a name="p348945124510"></a>验è¯å„功能点的基本功能/基本DFX属性在常规输入/常è§å¼‚常情况下的表现,通过表示功能基本æ£å¸¸å¯ç”¨ï¼Œå¯å¼€å±•Beta。</p> </td> </tr> <tr id="row48571137204514"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p7481545184513"><a name="p7481545184513"></a><a name="p7481545184513"></a>Level3</p> </td> <td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p1748184514455"><a name="p1748184514455"></a><a name="p1748184514455"></a>一般</p> </td> <td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p8481245104519"><a name="p8481245104519"></a><a name="p8481245104519"></a>验è¯å„功能点的全部功能/全部DFX属性在å„ç§å¸¸è§„/éžå¸¸è§„输入组åˆä¸‹ï¼Œæˆ–å„ç§æ£å¸¸/异常预置æ¡ä»¶ç»„åˆä¸‹çš„表现。</p> </td> </tr> <tr id="row14857133712451"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p1248144515456"><a name="p1248144515456"></a><a name="p1248144515456"></a>Level4</p> </td> <td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p94804514519"><a name="p94804514519"></a><a name="p94804514519"></a>生僻</p> </td> <td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p1248445164516"><a name="p1248445164516"></a><a name="p1248445164516"></a>验è¯å…³é”®åŠŸèƒ½ç‚¹åœ¨æžç«¯å¼‚常预置æ¡ä»¶ä¸‹ã€ç”¨æˆ·éš¾ä»¥è§¦åŠçš„异常输入组åˆä¸‹çš„表现。</p> </td> </tr> </tbody> </table> **表 2** 用例粒度说明 <a name="table1690733521014"></a> <table><thead align="left"><tr id="row9907143516105"><th class="cellrowborder" valign="top" width="19.591959195919593%" id="mcps1.2.4.1.1"><p id="p1141312416102"><a name="p1141312416102"></a><a name="p1141312416102"></a>用例规模</p> </th> <th class="cellrowborder" valign="top" width="35.17351735173517%" id="mcps1.2.4.1.2"><p id="p34131416109"><a name="p34131416109"></a><a name="p34131416109"></a>被测试对象</p> </th> <th class="cellrowborder" valign="top" width="45.23452345234523%" id="mcps1.2.4.1.3"><p id="p12413141171010"><a name="p12413141171010"></a><a name="p12413141171010"></a>测试环境</p> </th> </tr> </thead> <tbody><tr id="row2907335181017"><td class="cellrowborder" valign="top" width="19.591959195919593%" headers="mcps1.2.4.1.1 "><p id="p6414134117109"><a name="p6414134117109"></a><a name="p6414134117109"></a>LargeTest</p> </td> <td class="cellrowborder" valign="top" width="35.17351735173517%" headers="mcps1.2.4.1.2 "><p id="p20414104113101"><a name="p20414104113101"></a><a name="p20414104113101"></a>业务功能/全场景特性/整机åŠåœºæ™¯çº§DFX</p> </td> <td class="cellrowborder" valign="top" width="45.23452345234523%" headers="mcps1.2.4.1.3 "><p id="p5414841121013"><a name="p5414841121013"></a><a name="p5414841121013"></a>å°½é‡ä½¿ç”¨è´´è¿‘真实的环境设备</p> </td> </tr> <tr id="row10907635131015"><td class="cellrowborder" valign="top" width="19.591959195919593%" headers="mcps1.2.4.1.1 "><p id="p19414134117104"><a name="p19414134117104"></a><a name="p19414134117104"></a>MediumTest</p> </td> <td class="cellrowborder" valign="top" width="35.17351735173517%" headers="mcps1.2.4.1.2 "><p id="p114141241141018"><a name="p114141241141018"></a><a name="p114141241141018"></a>模å—/å系统集æˆè‡³è®¾å¤‡åŽçš„功能/DFX</p> </td> <td class="cellrowborder" valign="top" width="45.23452345234523%" headers="mcps1.2.4.1.3 "><p id="p14414941111015"><a name="p14414941111015"></a><a name="p14414941111015"></a>使用真实的å•è®¾å¤‡è¿›è¡ŒéªŒè¯ï¼Œå¯è¿›è¡Œæ¶ˆæ¯æ¨¡æ‹Ÿï¼Œå°½é‡ä¸å¯¹å‡½æ•°è¿›è¡ŒMOCK</p> </td> </tr> <tr id="row1990713353100"><td class="cellrowborder" valign="top" width="19.591959195919593%" headers="mcps1.2.4.1.1 "><p id="p641414110109"><a name="p641414110109"></a><a name="p641414110109"></a>SmallTest</p> </td> <td class="cellrowborder" valign="top" width="35.17351735173517%" headers="mcps1.2.4.1.2 "><p id="p54141541181018"><a name="p54141541181018"></a><a name="p54141541181018"></a>模å—/ç±»/函数</p> </td> <td class="cellrowborder" valign="top" width="45.23452345234523%" headers="mcps1.2.4.1.3 "><p id="p1841494131013"><a name="p1841494131013"></a><a name="p1841494131013"></a>在开å‘者个人环境进行测试,尽é‡ä¸ä¾èµ–其他模å—,å˜åœ¨å¤§é‡çš„MOCK</p> </td> </tr> </tbody> </table> **表 3** 测试类型说明 <a name="table18811230124619"></a> <table><thead align="left"><tr id="row48163019466"><th class="cellrowborder" valign="top" width="19.040000000000003%" id="mcps1.2.3.1.1"><p id="p1791784418465"><a name="p1791784418465"></a><a name="p1791784418465"></a>测试类型å称</p> </th> <th class="cellrowborder" valign="top" width="80.96%" id="mcps1.2.3.1.2"><p id="p2917164444614"><a name="p2917164444614"></a><a name="p2917164444614"></a>测试类型定义</p> </th> </tr> </thead> <tbody><tr id="row682630104615"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p1091784414469"><a name="p1091784414469"></a><a name="p1091784414469"></a>Function</p> </td> <td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p16917344104618"><a name="p16917344104618"></a><a name="p16917344104618"></a>验è¯è¢«æµ‹å¯¹è±¡æ供给用户的业务功能实现æ£ç¡®æ€§çš„测试项,这里的“用户â€å¯ä»¥æ˜¯ç»ˆç«¯ç”¨æˆ·æˆ–å¼€å‘者,功能包括业务功能åŠå¹³å°åŠŸèƒ½</p> </td> </tr> <tr id="row1821930154611"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p591714474612"><a name="p591714474612"></a><a name="p591714474612"></a>Performance</p> </td> <td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p15917154410463"><a name="p15917154410463"></a><a name="p15917154410463"></a>验è¯è¢«æµ‹å¯¹è±¡åœ¨ç‰¹å®šé¢„ç½®æ¡ä»¶/负载模型下的处ç†èƒ½åŠ›çš„测试项,“处ç†èƒ½åŠ›â€ä¸€èˆ¬ä»¥å•ä½æ—¶é—´å†…å¯å¤„ç†çš„业务é‡æ¥è¡¡é‡ï¼Œå¦‚呼å«/秒,帧率/秒,事件处ç†é‡/秒ç‰</p> </td> </tr> <tr id="row13821030104616"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p691711440467"><a name="p691711440467"></a><a name="p691711440467"></a>Power</p> </td> <td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p159171544104616"><a name="p159171544104616"></a><a name="p159171544104616"></a>验è¯è¢«æµ‹å¯¹è±¡åœ¨ç‰¹å®šé¢„ç½®æ¡ä»¶/负载模型下在一定时间内能æºæ¶ˆè€—é‡çš„测试项</p> </td> </tr> <tr id="row6821330114618"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p13917164454612"><a name="p13917164454612"></a><a name="p13917164454612"></a>Reliability</p> </td> <td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p11917194416465"><a name="p11917194416465"></a><a name="p11917194416465"></a>验è¯è¢«æµ‹å¯¹è±¡åœ¨æ£å¸¸/异常输入情况下,或业务é‡åŽ‹åŠ›å’Œé•¿æ—¶é—´è¿žç»è¿è¡ŒåŽ‹åŠ›æƒ…况下业务表现的测试项,å«ç¨³å®šæ€§ã€åŽ‹åŠ›ã€æ•…障注入ã€Monkey测试项</p> </td> </tr> <tr id="row11821930184612"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p1691774474618"><a name="p1691774474618"></a><a name="p1691774474618"></a>Security</p> </td> <td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p1791784410463"><a name="p1791784410463"></a><a name="p1791784410463"></a>验è¯ç³»ç»Ÿå¯¹æ¶æ„å¨èƒçš„防护能力,å¨èƒåŒ…括但ä¸é™äºŽæœªæŽˆæƒè®¿é—®ã€ä½¿ç”¨ã€æ³„露ã€ç ´åã€ä¿®æ”¹ã€æ¯ç,以ä¿éšœä¿¡æ¯çš„机密性ã€å®Œæ•´æ€§å’Œå¯ç”¨æ€§; 验è¯ç³»ç»Ÿå¯¹ç”¨æˆ·éšç§çš„ä¿æŠ¤èƒ½åŠ›ï¼Œä¿éšœç”¨æˆ·çš„éšç§æ•°æ®è¢«æ”¶é›†ã€ä½¿ç”¨ã€ä¿æœ‰ã€æŠ«éœ²å’Œå¤„置符åˆæ³•å¾‹è§„范,ä¿éšœç”¨æˆ·çš„éšç§æƒ; 验è¯å¯¹å„类安全规范的éµä»Žæƒ…况,如安全设计规范ã€å®‰å…¨çº¢çº¿ã€å·¥ä¿¡éƒ¨å®‰å…¨è®¤è¯è§„范ç‰ï¼Œä¿éšœå®‰å…¨ç›¸å…³æ³•å¾‹æ³•è§„çš„åˆè§„。</p> </td> </tr> <tr id="row16825307467"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p129188444462"><a name="p129188444462"></a><a name="p129188444462"></a>Global</p> </td> <td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p179186444465"><a name="p179186444465"></a><a name="p179186444465"></a>验è¯è¢«æµ‹å¯¹è±¡åœ¨æ˜¯å¦å…·æœ‰å›½é™…化数æ®æ”¯æŒå’Œæœ¬åœ°åŒ–能力的测试项,包括è¯è¨€æ˜¾ç¤ºã€è¾“å…¥/è¾“å‡ºä¹ æƒ¯ã€æ—¶é—´æ˜¾ç¤ºã€åŒºåŸŸç‰¹æ€§å¦‚è´§å¸æ—¶é—´ç¦å¿Œç‰ç‰</p> </td> </tr> <tr id="row08211308464"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p191814447465"><a name="p191814447465"></a><a name="p191814447465"></a>Compatibility</p> </td> <td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p99181344144613"><a name="p99181344144613"></a><a name="p99181344144613"></a>当被测对象为应用时,包括被测对象对于自身数æ®çš„åŽå‘兼容性ã€å¯¹äºŽç³»ç»Ÿçš„å‰åŽå‘兼容性ã€å¯¹äºŽä¸åŒç”¨æˆ·æ•°æ®(如æ’æ”¾å™¨ä¹‹éŸ³é¢‘æ–‡ä»¶æ ¼å¼/智能çŸä¿¡ä¹‹ç”¨æˆ·çŸä¿¡å†…容)的兼容性测试项; 当被测对象为系统时,包括被测系统对于系统自身数æ®çš„åŽå‘兼容性ã€ä»¥åŠå¯¹äºŽç”Ÿæ€ä¸å¸¸ç”¨åº”用的兼容性测试项;当被测对象为软件时,包括被测系统对于相关的硬件的兼容性;</p> </td> </tr> <tr id="row1782730124618"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p13918144134614"><a name="p13918144134614"></a><a name="p13918144134614"></a>User</p> </td> <td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p1291844494611"><a name="p1291844494611"></a><a name="p1291844494611"></a>验è¯è¢«æµ‹å¯¹è±¡åœ¨çœŸå®žç”¨æˆ·åœºæ™¯ä¸‹çš„用户体验感å—的测试项,注æ„æ¤ç§æƒ…况下没有客观的“æ£ç¡®â€ä¸Žâ€œå¤±è´¥â€ï¼Œæ‰€æœ‰çš„结论åŠè¯„价都应该æ¥è‡ªäºŽç”¨æˆ·</p> </td> </tr> <tr id="row58243024617"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p1291884474614"><a name="p1291884474614"></a><a name="p1291884474614"></a>Standard</p> </td> <td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p0918124424614"><a name="p0918124424614"></a><a name="p0918124424614"></a>验è¯è¢«æµ‹å¯¹è±¡å¯¹äºŽè¡Œä¸šåŠå…¬å¸å†…æ ‡å‡†/åè®®/规范的éµä»Žæƒ…况的测试项,注æ„æ¤å¤„çš„â€œæ ‡å‡†â€ä¸åŒ…å«ä»»ä½•å®‰å…¨æ ‡å‡†ï¼Œé’ˆå¯¹å®‰å…¨æ ‡å‡†çš„测试项划归为“安全测试â€ç±»åž‹</p> </td> </tr> <tr id="row382830124619"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p119181044164619"><a name="p119181044164619"></a><a name="p119181044164619"></a>Safety</p> </td> <td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p1291818443468"><a name="p1291818443468"></a><a name="p1291818443468"></a>验è¯è¢«æµ‹å¯¹è±¡çš„Safety属性,é¿å…产å“å¯èƒ½å¯¹äººèº«å®‰å…¨ã€å¥åº·ä»¥åŠäº§å“本身带æ¥çš„å±å®³ã€‚</p> </td> </tr> <tr id="row1083153014465"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p39187441469"><a name="p39187441469"></a><a name="p39187441469"></a>Resilience</p> </td> <td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p891815444462"><a name="p891815444462"></a><a name="p891815444462"></a>验è¯è¢«æµ‹å¯¹è±¡çš„韧性属性,确ä¿ç³»ç»Ÿå—攻击时承å—并ä¿æŒåœ¨æœ‰å®šä¹‰çš„è¿è¡ŒçŠ¶æ€ï¼ˆåŒ…括é™çº§ï¼‰ã€æ¢å¤å¹¶é€‚应攻击以ä¿éšœMissionè¾¾æˆã€‚</p> </td> </tr> </tbody> </table> ## 用例开å‘指导<a name="section3695134065513"></a> æ ¹æ®æµ‹è¯•ç³»ç»Ÿé€‰æ‹©æµ‹è¯•æ¡†æž¶å’Œå¯¹åº”测试用例è¯è¨€ã€‚ **表 4** 系统和测试框架ã€å¼€å‘è¯è¨€å¯¹åº”关系 <a name="table4418343171415"></a> <table><thead align="left"><tr id="row34183435145"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p941874311148"><a name="p941874311148"></a><a name="p941874311148"></a>系统</p> </th> <th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p1841804341413"><a name="p1841804341413"></a><a name="p1841804341413"></a>测试框架</p> </th> <th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p2418104311148"><a name="p2418104311148"></a><a name="p2418104311148"></a>è¯è¨€</p> </th> </tr> </thead> <tbody><tr id="row8419164319148"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p7419194312143"><a name="p7419194312143"></a><a name="p7419194312143"></a>è½»é‡ç³»ç»Ÿ</p> </td> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419124312145"><a name="p10419124312145"></a><a name="p10419124312145"></a>hctest</p> </td> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p11419643191410"><a name="p11419643191410"></a><a name="p11419643191410"></a>c</p> </td> </tr> <tr id="row141915438147"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p441911436141"><a name="p441911436141"></a><a name="p441911436141"></a>å°åž‹ç³»ç»Ÿ</p> </td> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p541916432142"><a name="p541916432142"></a><a name="p541916432142"></a>hcpptest</p> </td> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p54191643131416"><a name="p54191643131416"></a><a name="p54191643131416"></a>c++</p> </td> </tr> <tr id="row4419134341417"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p341964313143"><a name="p341964313143"></a><a name="p341964313143"></a>æ ‡å‡†ç³»ç»Ÿ</p> </td> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419443171416"><a name="p10419443171416"></a><a name="p10419443171416"></a>HJSUnitã€hcpptest</p> </td> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p9419143181414"><a name="p9419143181414"></a><a name="p9419143181414"></a>jsã€c++</p> </td> </tr> </tbody> </table> ### Cè¯è¨€ç”¨ä¾‹å¼€å‘编译指导(适用于轻é‡ç³»ç»Ÿäº§å“用例开å‘)<a name="section198193336544"></a> **示例:轻é‡ç³»ç»Ÿæµ‹è¯•ç”¨ä¾‹å¼€å‘** 当å‰ä½¿ç”¨çš„测试框架是hctest,hctest测试框架支æŒä½¿ç”¨Cè¯è¨€ç¼–写测试用例,是在开æºæµ‹è¯•æ¡†æž¶unity的基础上进行增强和适é…。 1. 用例目录规范:测试用例å˜å‚¨åˆ°test/xts/actsä»“ä¸ ``` ├── acts │ └──subsystem_lite │ │ └── module_hal │ │ │ └── BUILD.gn │ │ │ └── src │ └──build_lite │ │ └── BUILD.gn ``` 2. srcç›®å½•ä¸‹ç”¨ä¾‹ç¼–å†™æ ·ä¾‹ã€‚ 1.引用测试框架 ``` #include "hctest.h" ``` 2. 使用å®å®šä¹‰LITE\_TEST\_SUIT定义å系统ã€æ¨¡å—ã€æµ‹è¯•å¥—件å称 ``` /** * @brief register a test suit named "IntTestSuite" * @param test subsystem name * @param example module name * @param IntTestSuite test suit name */ LITE_TEST_SUIT(test, example, IntTestSuite); ``` 3. 定义Setup与TearDown 命åæ–¹å¼ï¼šæµ‹è¯•å¥—件å称+Setup,测试套件å称+TearDown。 Setup与TearDownå¿…é¡»å˜åœ¨ï¼Œå¯ä»¥ä¸ºç©ºå‡½æ•°ã€‚ 4. 使用å®å®šä¹‰LITE\_TEST\_CASE写测试用例 包括三个å‚数:测试套件å称,测试用例å称,用例属性(测试类型ã€ç”¨ä¾‹ç²’度ã€ç”¨ä¾‹çº§åˆ«ï¼‰ã€‚ ``` LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1) { //do something }; ``` 5. 使用å®å®šä¹‰ RUN\_TEST\_SUITE注册测试套件 ``` RUN_TEST_SUITE(IntTestSuite); ``` 3. 测试模å—çš„é…置文件(BUILD.gnï¼‰æ ·ä¾‹ï¼š 在æ¯ä¸ªæµ‹è¯•æ¨¡å—目录下新建BUILD.gn编译文件,用于指定编译åŽé™æ€åº“çš„å称ã€ä¾èµ–的头文件ã€ä¾èµ–的库ç‰ï¼›å…·ä½“写法如下: ``` import("//test/xts/tools/lite/build/suite_lite.gni") hctest_suite("ActsDemoTest") { suite_name = "acts" sources = [ "src/test_demo.c", ] include_dirs = [ ] cflags = [ "-Wno-error" ] } ``` 4. acts下BUILD.gnå¢žåŠ ç¼–è¯‘é€‰é¡¹ã€‚ 需è¦å°†æµ‹è¯•æ¨¡å—åŠ å…¥åˆ°acts目录下的编译脚本ä¸ï¼Œç¼–译脚本路径:test/xts/acts/build\_lite/BUILD.gn。 ``` lite_component("acts") { ... if(board_name == "liteos_m") { features += [ ... "//xts/acts/subsystem_lite/module_hal:ActsDemoTest" ] } } ``` 5. 测试套件编译命令_两ç§ç¼–译方å¼ã€‚ æ–¹å¼ä¸€ï¼š ``` ./test/xts/tools/lite/build.sh product=wifiiot xts=acts ``` æ–¹å¼äºŒï¼š ``` hb set 选择 设备类型 hb build --gn-args build_xts=true (注):若ä¸è¿½åŠ --gn-args build_xts=true,ä¸ä¼šç¼–译acts测试套件。 ``` >![](figures/icon-note.gif) **说明:** >acts测试套件编译ä¸é—´ä»¶ä¸ºé™æ€åº“,最终链接到版本镜åƒä¸ 。 ### Cè¯è¨€ç”¨ä¾‹æ‰§è¡ŒæŒ‡å¯¼ï¼ˆé€‚用于轻é‡ç³»ç»Ÿäº§å“用例开å‘)<a name="section13820233175418"></a> **示例:轻é‡ç³»ç»Ÿæµ‹è¯•ç”¨ä¾‹æ‰§è¡Œ** 将版本镜åƒçƒ§å½•è¿›å¼€å‘æ¿ã€‚ **测试æ¥éª¤** 1. 使用串å£å·¥å…·ç™»å½•å¼€å‘æ¿ï¼Œå¹¶ä¿å˜ä¸²å£æ‰“å°ä¿¡æ¯ã€‚ 2. é‡å¯è®¾å¤‡ï¼ŒæŸ¥çœ‹ä¸²å£æ—¥å¿—。 **测试结果分æžæŒ‡å¯¼** 基于串å£æ‰“å°æ—¥å¿—进行分æžï¼› æ¯ä¸ªæµ‹è¯•å¥—件执行以Start to run test suite开始,以xx Tests xx Failures xx Ignored结æŸã€‚ ### C++è¯è¨€ç”¨ä¾‹å¼€å‘编译指导(适用于å°åž‹ç³»ç»Ÿã€æ ‡å‡†ç³»ç»Ÿç”¨ä¾‹å¼€å‘)<a name="section3822123311540"></a> **示例:å°åž‹ç³»ç»Ÿæµ‹è¯•ç”¨ä¾‹å¼€å‘**ï¼ˆæ ‡å‡†ç³»ç»Ÿå‚è€ƒå…·ä½“æ ·ä¾‹ç›®å½•ï¼šglobal/i18n\_standard) 当å‰ä½¿ç”¨çš„测试框架是hcpptest,hcpptest测试框架是在开æºçš„googletest测试框架的基础上进行的增强和适é…。 1. 规范用例目录:测试用例å˜å‚¨åˆ°test/xts/acts仓ä¸ã€‚ ``` ├── acts │ └──subsystem_lite │ │ └── module_posix │ │ │ └── BUILD.gn │ │ │ └── src │ └──build_lite │ │ └── BUILD.gn ``` 2. 测试模å—srcä¸‹ç”¨ä¾‹ç¼–å†™æ ·ä¾‹ï¼š 1. 引用测试框架: 需è¦å¼•ç”¨gtest.h 如:\#include "gtest/gtest.h" ``` #include "gtest/gtest.h" ``` 2. 定义Setup与TearDown ``` using namespace std; using namespace testing::ext; class TestSuite: public testing::Test { protected: // Preset action of the test suite, which is executed before the first test case static void SetUpTestCase(void){ } // Test suite cleanup action, which is executed after the last test case static void TearDownTestCase(void){ } // Preset action of the test case virtual void SetUp() { } // Cleanup action of the test case virtual void TearDown() { } }; ``` 3. 使用å®å®šä¹‰HWTEST或HWTEST\_F写测试用例 普通测试用例的定义:HWTEST(测试套å称, 测试用例å称, ç”¨ä¾‹æ ‡æ³¨ï¼‰ã€‚ 包å«SetUpå’ŒTearDown的测试用例的定义 :HWTEST\_F(测试套å称, 测试用例åç§°ï¼Œç”¨ä¾‹æ ‡æ³¨ï¼‰ã€‚ å®å®šä¹‰åŒ…括三个å‚数:测试套件å称,测试用例å称,用例属性(测试类型ã€ç”¨ä¾‹ç²’度ã€ç”¨ä¾‹çº§åˆ«ï¼‰ã€‚ ``` HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) { // do something } ``` 3. 测试模å—下用例é…置文件(BUILD.gnï¼‰æ ·ä¾‹ï¼š æ¯ä¸ªæµ‹è¯•æ¨¡å—目录下新建BUILD.gn编译文件,用于指定编译åŽå¯æ‰§è¡Œæ–‡ä»¶çš„å称ã€ä¾èµ–的头文件ã€ä¾èµ–的库ç‰ï¼›å…·ä½“写法如下。æ¯ä¸ªæµ‹è¯•æ¨¡å—将独立编译æˆ.binå¯æ‰§è¡Œæ–‡ä»¶ï¼Œ 该文件å¯ç›´æŽ¥push到å•æ¿ä¸Šè¿›è¡Œæµ‹è¯•ã€‚ 举例: ``` import("//test/xts/tools/lite/build/suite_lite.gni") hcpptest_suite("ActsDemoTest") { suite_name = "acts" sources = [ "src/TestDemo.cpp" ] include_dirs = [ "src", ... ] deps = [ ... ] cflags = [ "-Wno-error" ] } ``` 4. actsç›®å½•ä¸‹å¢žåŠ ç¼–è¯‘é€‰é¡¹ï¼ˆBUILD.gnï¼‰æ ·ä¾‹ï¼š 将测试模å—åŠ å…¥åˆ°acts目录下的编译脚本ä¸ï¼Œç¼–译脚本为:test/xts/acts/build\_lite/BUILD.gn。 ``` lite_component("acts") { ... else if(board_name == "liteos_a") { features += [ ... "//xts/acts/subsystem_lite/module_posix:ActsDemoTest" ] } } ``` 5. 测试套件编译命令_两ç§ç¼–译方å¼ã€‚ L1_LiteOS: ``` æ–¹å¼ä¸€ï¼š python3 build.py -p ipcamera_hispark_taurus@hisilicon --gn-args build_xts=true æ–¹å¼äºŒï¼š hb set 选择 设备类型 hb build --gn-args build_xts=true (注):若ä¸è¿½åŠ --gn-args build_xts=true,ä¸ä¼šç¼–译acts测试套件。 ``` L1_Linux: ``` æ–¹å¼ä¸€ï¼š python3 build.py -p ipcamera_hispark_taurus_linux@hisilicon --gn-args build_xts=true æ–¹å¼äºŒï¼š hb set 选择 设备类型 hb build --gn-args build_xts=true (注):若ä¸è¿½åŠ --gn-args build_xts=true,ä¸ä¼šç¼–译acts测试套件。 ``` >![](figures/icon-note.gif) **说明:** >å°åž‹ç³»ç»Ÿacts独立编译æˆå¯æ‰§è¡Œæ–‡ä»¶ï¼ˆbinæ ¼å¼ï¼‰ï¼Œ 在编译产物的suites\\acts目录下归档。 ### C++è¯è¨€ç”¨ä¾‹æ‰§è¡ŒæŒ‡å¯¼ï¼ˆé€‚用于å°åž‹ç³»ç»Ÿã€æ ‡å‡†ç³»ç»Ÿç”¨ä¾‹å¼€å‘)<a name="section128222336544"></a> **示例:å°åž‹ç³»ç»Ÿæµ‹è¯•ç”¨ä¾‹æ‰§è¡Œ** ç›®å‰çš„用例执行采用nfs共享的方å¼ï¼Œmount到å•æ¿åŽ»æ‰§è¡Œã€‚ **环境æ建** 1. ä½¿ç”¨ç½‘çº¿æˆ–æ— çº¿ç½‘ç»œå°†å¼€å‘æ¿ä¸ŽPC进行连接。 2. å¼€å‘æ¿é…ç½®IPã€å网掩ç ã€ç½‘关,确ä¿å¼€å‘æ¿ä¸ŽPC处于åŒä¸€ä¸ªç½‘段。 3. PC安装nfsæœåŠ¡å™¨å¹¶å®Œæˆæ³¨å†Œï¼Œå¯åŠ¨nfsæœåŠ¡ã€‚ 4. å¼€å‘æ¿é…ç½®mount命令,确ä¿å¼€å‘æ¿å¯ä»¥è®¿é—®PC端的nfs共享文件。 æ ¼å¼ï¼šmount \[nfsæœåŠ¡å™¨IP\]:\[/nfs共享目录\] \[/å¼€å‘æ¿ç›®å½•\] nfs 举例: ``` mount 192.168.1.10:/nfs /nfs nfs ``` **用例执行** 测试套件执行 ActsDemoTest.bin 触å‘用例执行,基于串å£æ‰“å°æ—¥å¿—进行分æžã€‚ ### JSè¯è¨€ç”¨ä¾‹å¼€å‘æŒ‡å¯¼ï¼ˆé€‚ç”¨äºŽæ ‡å‡†ç³»ç»Ÿï¼‰<a name="section159801435165220"></a> 当å‰ä½¿ç”¨çš„测试框架是HJSUnit,用于支撑OpenHarmony application测试(特指基于JS应用框架使用 Javascript è¯è¨€å¼€å‘çš„ APP)进行自动化测试。 **用例编写基础è¯æ³•** 测试用例为 js è¯è¨€ï¼Œå¿…须满足 JavaScript è¯è¨€ç¼–程规范: **表 5** <a name="table13980103565212"></a> <table><thead align="left"><tr id="row1098093545218"><th class="cellrowborder" valign="top" width="17.92179217921792%" id="mcps1.2.4.1.1"><p id="p49811235135214"><a name="p49811235135214"></a><a name="p49811235135214"></a>用例è¯æ³•</p> </th> <th class="cellrowborder" valign="top" width="68.88688868886888%" id="mcps1.2.4.1.2"><p id="p898183565220"><a name="p898183565220"></a><a name="p898183565220"></a>æè¿°</p> </th> <th class="cellrowborder" valign="top" width="13.19131913191319%" id="mcps1.2.4.1.3"><p id="p17981143512526"><a name="p17981143512526"></a><a name="p17981143512526"></a>è¦æ±‚</p> </th> </tr> </thead> <tbody><tr id="row1598183515528"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p139810358527"><a name="p139810358527"></a><a name="p139810358527"></a>beforeAll</p> </td> <td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p198111352526"><a name="p198111352526"></a><a name="p198111352526"></a>测试套级别的预置æ¡ä»¶ï¼Œåœ¨æ‰€æœ‰æµ‹è¯•ç”¨ä¾‹å¼€å§‹å‰æ‰§è¡Œä¸”仅执行一次,支æŒä¸€ä¸ªå‚数:预置动作函数</p> </td> <td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p298114355529"><a name="p298114355529"></a><a name="p298114355529"></a>å¯é€‰</p> </td> </tr> <tr id="row11981103512529"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p20981135135215"><a name="p20981135135215"></a><a name="p20981135135215"></a>afterAll</p> </td> <td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p39811935115217"><a name="p39811935115217"></a><a name="p39811935115217"></a>测试套级别的清ç†æ¡ä»¶ï¼Œåœ¨æ‰€æœ‰æµ‹è¯•ç”¨ä¾‹ç»“æŸåŽæ‰§è¡Œä¸”仅执行一次,支æŒä¸€ä¸ªå‚数:清ç†åŠ¨ä½œå‡½æ•°</p> </td> <td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p998110354527"><a name="p998110354527"></a><a name="p998110354527"></a>å¯é€‰</p> </td> </tr> <tr id="row1298116359526"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p898112359526"><a name="p898112359526"></a><a name="p898112359526"></a>beforeEach</p> </td> <td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p149811335175215"><a name="p149811335175215"></a><a name="p149811335175215"></a>测试用例级别的预置æ¡ä»¶ï¼Œåœ¨æ¯æ¡æµ‹è¯•ç”¨ä¾‹å¼€å§‹å‰æ‰§è¡Œï¼Œæ‰§è¡Œæ¬¡æ•°ä¸Ž it 定义的测试用例数一致,支æŒä¸€ä¸ªå‚数:预置动作函数</p> </td> <td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p13981133585212"><a name="p13981133585212"></a><a name="p13981133585212"></a>å¯é€‰</p> </td> </tr> <tr id="row6982435115219"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p19982133517525"><a name="p19982133517525"></a><a name="p19982133517525"></a>afterEach</p> </td> <td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p1398213575219"><a name="p1398213575219"></a><a name="p1398213575219"></a>测试用例级别的清ç†æ¡ä»¶ï¼Œåœ¨æ¯æ¡æµ‹è¯•ç”¨ä¾‹ç»“æŸåŽæ‰§è¡Œï¼Œæ‰§è¡Œæ¬¡æ•°ä¸Ž it 定义的测试用例数一致,支æŒä¸€ä¸ªå‚数:清ç†åŠ¨ä½œå‡½æ•°</p> </td> <td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p159821535195219"><a name="p159821535195219"></a><a name="p159821535195219"></a>å¯é€‰</p> </td> </tr> <tr id="row16982143513521"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p598203510527"><a name="p598203510527"></a><a name="p598203510527"></a>describe</p> </td> <td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p5982123595215"><a name="p5982123595215"></a><a name="p5982123595215"></a>定义一个测试套,支æŒä¸¤ä¸ªå‚数:测试套å称和测试套函数; describe 支æŒåµŒå¥—,æ¯ä¸ª describe 内å‡å¯ä»¥å®šä¹‰ beforeAll ã€beforeEach ã€afterEach å’Œ afterAll</p> </td> <td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p898217352527"><a name="p898217352527"></a><a name="p898217352527"></a>必选</p> </td> </tr> <tr id="row6982113518526"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p17982123510526"><a name="p17982123510526"></a><a name="p17982123510526"></a>it</p> </td> <td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p598211352522"><a name="p598211352522"></a><a name="p598211352522"></a>定义一æ¡æµ‹è¯•ç”¨ä¾‹ï¼Œæ”¯æŒä¸‰ä¸ªå‚数:用例å称,过滤å‚数和用例函数</p> <p id="p5205769588"><a name="p5205769588"></a><a name="p5205769588"></a>备注:</p> <p id="p6965058101"><a name="p6965058101"></a><a name="p6965058101"></a>过滤å‚数:过滤å‚数为一个 32 ä½çš„ Int 类型å‚数,0 ä½ ç½®1表示ä¸ç›é€‰ã€é»˜è®¤æ‰§è¡Œï¼›0-10 ä½ ç½®1表示<strong id="b9169154410212"><a name="b9169154410212"></a><a name="b9169154410212"></a>测试用例类型</strong>ï¼›16-18 ä½ ç½®1表示<strong id="b1427947428"><a name="b1427947428"></a><a name="b1427947428"></a>测试用例规模</strong>ï¼›24-28 ä½ ç½®1表示<strong id="b289818491213"><a name="b289818491213"></a><a name="b289818491213"></a>测试层级</strong>。</p> <p id="p7965165151011"><a name="p7965165151011"></a><a name="p7965165151011"></a><strong id="b69449534215"><a name="b69449534215"></a><a name="b69449534215"></a>测试用例类型</strong>。置ä½0-10分别表示:FUNCTION 方法类测试ã€PERFORMANCE 性能类测试ã€POWER 功耗类测试ã€RELIABILITY å¯é 性测试ã€SECURITY 安全åˆè§„测试ã€GLOBAL 整体性测试ã€COMPATIBILITY 兼容性测试ã€USER 用户测试ã€STANDARD æ ‡å‡†æµ‹è¯•ã€SAFETY 安全特性测试,RESILIENCE 压力测试。</p> <p id="p199651555102"><a name="p199651555102"></a><a name="p199651555102"></a><strong id="b10114125712211"><a name="b10114125712211"></a><a name="b10114125712211"></a>测试用例规模</strong>。置ä½16-18分别表示:SMALL å°åž‹æµ‹è¯•ã€MEDIUM ä¸åž‹æµ‹è¯•ã€LARGE 大型测试。</p> <p id="p296545151020"><a name="p296545151020"></a><a name="p296545151020"></a><strong id="b167975581223"><a name="b167975581223"></a><a name="b167975581223"></a>测试层级</strong>。置ä½24-28分别表示:LEVEL0-0 级测试ã€LEVEL1-1 级测试ã€LEVEL2-2 级测试ã€LEVEL3-3 级测试ã€LEVEL4-4 级测试。</p> </td> <td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p17601752115716"><a name="p17601752115716"></a><a name="p17601752115716"></a>必选</p> </td> </tr> </tbody> </table> 用例编写è¯æ³•é‡‡ç”¨ jasmine çš„æ ‡å‡†è¯æ³•ï¼Œæ ¼å¼æ”¯æŒES6æ ¼å¼ã€‚ **以FA 模å¼ä¸ºä¾‹ï¼š** 1. 规范用例目录:测试用例å˜å‚¨åˆ° src/main/js/test目录。 ``` ├── BUILD.gn ├── Test.json # 资æºä¾èµ–hapä¸éœ€è¦Test.json文件 ├── signature │ └──openharmony_sx.p7b # ç¾å工具 └──src │ └──main │ │ └──js │ │ │ └──MainAbility │ │ │ │ └──app.js │ │ │ │ └──pages │ │ │ │ │ └──index │ │ │ │ │ │ └──index.js │ │ │ └──test # 测试代ç å˜æ”¾ç›®å½• │ │ │ │ │ └──List.test.js │ │ │ │ │ └──Ability.test.js │ │ │ └──TestAbility # 测试框架入å£æ¨¡æ¿æ–‡ä»¶ï¼Œæ·»åŠ åŽæ— 需修改 │ │ │ │ └──app.js │ │ │ │ └──pages │ │ │ │ │ └──index │ │ │ │ │ │ └──index.js │ │ │ └──TestRunner # 测试框架入å£æ¨¡æ¿æ–‡ä»¶ï¼Œæ·»åŠ åŽæ— 需修改 │ │ │ │ └──OpenHarmonyTestRunner.js │ └── resources # hap资æºå˜æ”¾ç›®å½• │ └── config.json # hapé…置文件 ``` 2. OpenHarmonyTestRunner.js 示例 ``` //åŠ è½½js 测试框架 import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' ... export default { ... onRun() { console.log('OpenHarmonyTestRunner onRun run') var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.MainAbility' var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName ... } }; ``` 3. index.js示例 ``` export default { ... onShow() { console.info('onShow finish!') }, ... } ``` 4. app.js示例 ``` //åŠ è½½æµ‹è¯•ç”¨ä¾‹ import { Hypium } from '@ohos/hypium' import testsuite from '../test/List.test' export default { onCreate() { console.info('TestApplication onCreate'); var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() console.info('start run testcase!!!') Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) }, ... }; ``` 5. å•å…ƒæµ‹è¯•ç”¨ä¾‹ç¤ºä¾‹ ``` // Example1: 使用HJSUnit进行å•å…ƒæµ‹è¯• describe('appInfoTest', function () { it('app_info_test_001', 0, function () { var info = app.getInfo() expect(info.versionName).assertEqual('1.0') expect(info.versionCode).assertEqual('3') }) }) ``` FA_JS 模å¼æµ‹è¯•æ¨¡å—下用例é…置文件(BUILD.gnï¼‰æ ·ä¾‹ï¼š ``` import("//test/xts/tools/build/suite.gni") ohos_js_hap_suite("ActsDemoTest") { hap_profile = "./src/main/config.json" deps = [ ":hjs_demo_js_assets", ":hjs_demo_resources", ] certificate_profile = "./signature/openharmony_sx.p7b" //ç¾å文件 hap_name = "ActsDemoTest" //测试套件,以Acts开头,以Test结尾,采用驼峰å¼å‘½å part_name = "..." //部件 subsystem_name = "..." //å系统 } ohos_js_assets("hjs_demo_js_assets") { js2abc = true hap_profile = "./src/main/config.json" source_dir = "./src/main/js" } ohos_resources("hjs_demo_resources") { sources = [ "./src/main/resources" ] hap_profile = "./src/main/config.json" } ``` FA_TS 模å¼æµ‹è¯•æ¨¡å—下用例é…置文件(BUILD.gnï¼‰æ ·ä¾‹ï¼š ``` import("//test/xts/tools/build/suite.gni") ohos_js_hap_suite("ActsDemoTest") { hap_profile = "./src/main/config.json" deps = [ ":ace_demo_ets_assets", ":ace_demo_ets_resources", ":ace_demo_ets_test_assets", ] ets2abc = true certificate_profile = "./signature/openharmony_sx.p7b" //ç¾å文件 hap_name = "ActsDemoTest" //测试套件,以Acts开头,以Test结尾,采用驼峰å¼å‘½å part_name = "..." //部件 subsystem_name = "..." //å系统 } ohos_js_assets("ace_demo_ets_assets") { source_dir = "./src/main/ets/MainAbility" } ohos_js_assets("ace_demo_ets_test_assets") { source_dir = "./src/main/ets/TestAbility" } ohos_resources("ace_demo_ets_resources") { sources = [ "./src/main/resources" ] hap_profile = "./src/main/config.json" } ``` FA_JS 模å¼é€‚é…指导请å‚考 ​ [JS工程目录结构(FA模型)](https://gitee.com/openharmony/xts_acts/wikis/XTS_%E7%99%BE%E7%A7%91%E6%8C%87%E5%AF%BC/JS%E5%B7%A5%E7%A8%8B%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84%EF%BC%88FA%E6%A8%A1%E5%9E%8B%EF%BC%89) FA_TS 模å¼é€‚é…指导请å‚考 ​ [eTS工程目录结构(FA模型)](https://gitee.com/openharmony/xts_acts/wikis/XTS_%E7%99%BE%E7%A7%91%E6%8C%87%E5%AF%BC/eTS%E5%B7%A5%E7%A8%8B%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84%EF%BC%88FA%E6%A8%A1%E5%9E%8B%EF%BC%89) **以Stage 模å¼ä¸ºä¾‹ï¼š** 1. 规范用例目录:测试用例å˜å‚¨åˆ° src/main/js/test目录。 ``` ├── BUILD.gn # é…置文件 ├── Test.json # 资æºä¾èµ–hapä¸éœ€è¦Test.json文件 ├── signature │ └──openharmony_sx.p7b # ç¾å工具 ├── AppScope │ └──resource │ └──app.json ├── entry │ └──src │ │ └──main │ │ │ └──ets │ │ │ │ └──test # 测试代ç å˜æ”¾ç›®å½• │ │ │ │ │ └──List.test.ets │ │ │ │ │ └──Ability.test.ets │ │ │ │ └──MainAbility │ │ │ │ │ └──MainAbility.ts │ │ │ │ │ └──pages │ │ │ │ │ │ └──index │ │ │ │ │ │ │ └──index.ets │ │ │ │ └──TestAbility │ │ │ │ │ └──TestAbility.ts # 测试用例å¯åŠ¨å…¥å£ ability │ │ │ │ │ └──pages │ │ │ │ │ │ └──index.ets │ │ │ │ └──Application │ │ │ │ │ └──AbilityStage.ts │ │ │ │ └──TestRunner # 测试框架入å£æ¨¡æ¿æ–‡ä»¶ï¼Œæ·»åŠ åŽæ— 需修改 │ │ │ │ │ └──OpenHarmonyTestRunner.js │ │ └── resources # hap资æºå˜æ”¾ç›®å½• │ │ └── module.json # hapé…置文件 ``` 2. OpenHarmonyTestRunner.ts 示例 ã€æ³¨ã€‘在TestRunner目录下的 OpenHarmonyTestRunner.ts 文件ä¸çš„ async onRun() 方法下å˜åœ¨æ‹‰èµ·æµ‹è¯•å¥—å…¥å£xxxAbilityçš„cmd 命令: 例如: var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName 需与module.jsonä¸ "abilities" 下的 "name" å—段ä¿æŒä¸€è‡´ï¼Œä¿è¯æ‹‰èµ·çš„是我们需è¦çš„测试入å£ã€‚ ``` import TestRunner from '@ohos.application.testRunner' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' ... export default class OpenHarmonyTestRunner implements TestRunner { ... async onRun() { console.log('OpenHarmonyTestRunner onRun run') abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' let lMonitor = { abilityName: testAbilityName, onAbilityCreate: onAbilityCreateCallback, }; abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName ... } }; ``` 3. index.ets示例 ``` import router from '@ohos.router'; @Entry @Component struct Index { aboutToAppear(){ console.info("start run testcase!!!!") } build() { ... } } ``` 4. app.js示例 ``` //åŠ è½½æµ‹è¯•ç”¨ä¾‹ import Ability from '@ohos.app.ability.UIAbility' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' import { Hypium } from '@ohos/hypium' import testsuite from '../test/List.test' export default class TestAbility extends Ability { onCreate(want, launchParam) { console.log('TestAbility onCreate') var abilityDelegator: any abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() var abilityDelegatorArguments: any abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() console.info('start run testcase!!!') Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) } ... }; ``` Stage 模å¼æµ‹è¯•æ¨¡å—下用例é…置文件(BUILD.gnï¼‰æ ·ä¾‹ï¼š ``` import("//test/xts/tools/build/suite.gni") ohos_js_hap_suite("ActsDemoTest") { hap_profile = "/src/main/module.json" js_build_mode = "debug" deps = [ ":edm_js_assets", ":edm_resources", ] ets2abc = true certificate_profile = "signature/openharmony_sx.p7b" //ç¾å文件 hap_name = "ActsDemoTest" //测试套件,以Acts开头,以Test结尾,采用驼峰å¼å‘½å subsystem_name = "customization" //å系统 part_name = "enterprise_device_management" //部件 } ohos_app_scope("edm_app_profile") { app_profile = "AppScope/app.json" sources = [ "AppScope/resources" ] } ohos_js_assets("edm_js_assets") { source_dir = "/src/main/ets" } ohos_resources("edm_resources") { sources = [ "/src/main/resources" ] deps = [ ":edm_app_profile" ] hap_profile = "/src/main/module.json" } ``` Stage 模å¼é€‚é…指导请å‚考 ​ [eTS工程目录结构(Stage模型)](https://gitee.com/openharmony/xts_acts/wikis/XTS_%E7%99%BE%E7%A7%91%E6%8C%87%E5%AF%BC/eTS%E5%B7%A5%E7%A8%8B%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84%EF%BC%88Stage%E6%A8%A1%E5%9E%8B%EF%BC%89) ### JSè¯è¨€ç”¨ä¾‹ç¼–è¯‘æ‰“åŒ…æŒ‡å¯¼ï¼ˆé€‚ç”¨äºŽæ ‡å‡†ç³»ç»Ÿï¼‰<a name="section445519106559"></a> hap包编译请å‚考 [æ ‡å‡†ç³»ç»Ÿ JS用例æºç 编译Hap包指导](https://gitee.com/openharmony/xts_acts/wikis/%E6%A0%87%E5%87%86%E7%B3%BB%E7%BB%9F%20JS%E7%94%A8%E4%BE%8B%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91Hap%E5%8C%85%E6%8C%87%E5%AF%BC%20?sort_id=4427112)。 ### å…¨é‡ç¼–è¯‘æŒ‡å¯¼ï¼ˆé€‚ç”¨äºŽæ ‡å‡†ç³»ç»Ÿï¼‰<a name="section159801435165220"></a> 1. å…¨é‡ç¼–译 test/xts/acts目录下执行编译命令: ``` ./build.sh product_name=rk3568 system_size=standard ``` 2. å•ä¸ªå系统编译 test/xts/acts目录下执行编译命令: ``` ./build.sh product_name=rk3568 system_size=standard target_subsystem=×××× ``` 3. å•æ¨¡å—编译 test/xts/acts目录下执行编译命令: ```./build.sh suite=acts system_size=standard target_subsystem=×××× ./build.sh product_name=rk3568 system_size=standard suite=xxx suite åŽé¢æ·»åŠ 的是BUILD.gn ä¸ohos_js_hap_suite模æ¿çš„命å ``` 测试用例输出目录:out/rk3568/suites/acts/testcases 测试框架&用例整体输出目录:out/rk3568/suites/acts(编译用例时会åŒæ¥ç¼–译测试套执行框架) ### å…¨é‡ç”¨ä¾‹æ‰§è¡ŒæŒ‡å¯¼ï¼ˆé€‚用于å°åž‹ç³»ç»Ÿã€æ ‡å‡†ç³»ç»Ÿï¼‰<a name="section159801435165220"></a> æ建测试环境Windows工作å°ä¸‹å®‰è£…python3.7åŠä»¥ä¸Šç‰ˆæœ¬ï¼Œç¡®ä¿å·¥ä½œå°å’Œæµ‹è¯•è®¾å¤‡æ£å¸¸è¿žæŽ¥ã€‚ **注:高版本pythonä¸å¸¦ easy_install,å¯ä»¥å®‰è£…低于 52.0.0 çš„ setuptools,解决该问题。** ``` pip install setuptools==50.0.0 ``` 测试执行目录(对应编译生æˆçš„out/release/suites/acts目录) ├── testcase # 测试套文件å˜æ”¾ç›®å½• │ └──xxx.hap # 测试套å¯æ‰§è¡Œhap文件 │ └──xxx.json # 测试套对应执行é…置文件 ├── tools # 测试框架工具目录 ├── run.bat # windowå¹³å°æµ‹è¯•å¥—å¯åŠ¨æ‰§è¡Œæ–‡ä»¶ ├── report # 测试报告生æˆç›®å½• 用例执行 1. 在Windows工作å°ä¸Šï¼Œæ‰¾åˆ°ä»ŽLinuxæœåŠ¡å™¨ä¸Šæ‹·è´ä¸‹æ¥çš„测试套件用例目录,在Windows命令窗å£è¿›å…¥å¯¹åº”目录,直接执行acts\run.bat。 2. ç•Œé¢å¯åŠ¨åŽï¼Œè¾“入用例执行指令。 å…¨é‡æ‰§è¡Œï¼š```run acts ``` 模å—执行(具体模å—å¯ä»¥æŸ¥çœ‹\acts\testcases\):```run –l ActsSamgrTest ``` å•åŒ…执行(具体模å—å¯ä»¥æŸ¥çœ‹\acts\testcases\):(适用于OH驱动) ``` run -l uitestActs -ta class:UiTestCase#testChecked uitestActs: 测试hap UiTestCase: testsuite testChecked: testcase ``` 3. 查看测试报告。 进入acts\reports\,获å–当å‰çš„执行记录,打开“summary_report.htmlâ€å¯ä»¥èŽ·å–到测试报告。 ## 相关仓<a name="section1371113476307"></a> **xts\_acts** [xts\_tools](https://gitee.com/openharmony/xts_tools)