1f6603c60Sopenharmony_ci# XTS<a name="EN-US_TOPIC_0000001126156429"></a> 2f6603c60Sopenharmony_ci 3f6603c60Sopenharmony_ci- [Introduction](#section465982318513) 4f6603c60Sopenharmony_ci- [System Types](#section125090457443) 5f6603c60Sopenharmony_ci- [Directory Structure](#section161941989596) 6f6603c60Sopenharmony_ci- [Constraints](#section119744591305) 7f6603c60Sopenharmony_ci- [Usage Guidelines](#section137768191623) 8f6603c60Sopenharmony_ci- [Test Case Development Guidelines](#section3695134065513) 9f6603c60Sopenharmony_ci - [C-based Test Case Development and Compilation \(for the Mini System\)](#section198193336544) 10f6603c60Sopenharmony_ci - [C-based Test Case Execution \(for the Mini System\)](#section13820233175418) 11f6603c60Sopenharmony_ci - [C++-based Test Case Development and Compilation \(for Standard and Small Systems\)](#section3822123311540) 12f6603c60Sopenharmony_ci - [C++-based Test Case Execution \(for Standard and Small Systems\)](#section128222336544) 13f6603c60Sopenharmony_ci - [JavaScript-based Test Case Development \(for the Standard System\)](#section159801435165220) 14f6603c60Sopenharmony_ci - [JavaScript-based Test Case Packaging \(for the Standard System\)](#section445519106559) 15f6603c60Sopenharmony_ci 16f6603c60Sopenharmony_ci 17f6603c60Sopenharmony_ci## Introduction<a name="section465982318513"></a> 18f6603c60Sopenharmony_ci 19f6603c60Sopenharmony_ciThe X test suite \(XTS\) subsystem contains a set of OpenHarmony certification test suites, including the currently supported application compatibility test suite \(ACTS\) and the device compatibility test suite \(DCTS\) that will be supported in the future. 20f6603c60Sopenharmony_ci 21f6603c60Sopenharmony_ciThis subsystem contains the ACTS and **tools** software package. 22f6603c60Sopenharmony_ci 23f6603c60Sopenharmony_ci- The **acts** directory stores the source code and configuration files of ACTS test cases. The ACTS helps device vendors detect the software incompatibility as early as possible and ensures that the software is compatible to OpenHarmony during the entire development process. 24f6603c60Sopenharmony_ci- The **tools** software package stores the test case development framework related to **acts**. 25f6603c60Sopenharmony_ci 26f6603c60Sopenharmony_ci## System Types<a name="section125090457443"></a> 27f6603c60Sopenharmony_ci 28f6603c60Sopenharmony_ciOpenHarmony supports the following system types: 29f6603c60Sopenharmony_ci 30f6603c60Sopenharmony_ci- Mini system 31f6603c60Sopenharmony_ci 32f6603c60Sopenharmony_ci A mini system runs on the devices whose memory is greater than or equal to 128 KiB and that are equipped with MCU processors such as ARM Cortex-M and 32-bit RISC-V. This system provides multiple lightweight network protocols and graphics frameworks, and a wide range of read/write components for the IoT bus. Typical products include connection modules, sensors, and wearables for smart home. 33f6603c60Sopenharmony_ci 34f6603c60Sopenharmony_ci- Small system 35f6603c60Sopenharmony_ci 36f6603c60Sopenharmony_ci A small system runs on the devices whose memory is greater than or equal to 1 MiB and that are equipped with application processors such as ARM Cortex-A. This system provides higher security capabilities, standard graphics frameworks, and video encoding and decoding capabilities. Typical products include smart home IP cameras, electronic cat eyes, and routers, and event data recorders \(EDRs\) for smart travel. 37f6603c60Sopenharmony_ci 38f6603c60Sopenharmony_ci- Standard system 39f6603c60Sopenharmony_ci 40f6603c60Sopenharmony_ci A standard system runs on the devices whose memory is greater than or equal to 128 MiB and that are equipped with application processors such as ARM Cortex-A. This system provides a complete application framework supporting the enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. This system applies to high-end refrigerator displays. 41f6603c60Sopenharmony_ci 42f6603c60Sopenharmony_ci 43f6603c60Sopenharmony_ci## Directory Structure<a name="section161941989596"></a> 44f6603c60Sopenharmony_ci 45f6603c60Sopenharmony_ci``` 46f6603c60Sopenharmony_ci/test/xts 47f6603c60Sopenharmony_ci├── acts # Test code 48f6603c60Sopenharmony_ci│ └── subsystem # Source code of subsystem test cases for the standard system 49f6603c60Sopenharmony_ci│ └── subsystem_lite # Source code of subsystems test cases for mini and small systems 50f6603c60Sopenharmony_ci│ └── BUILD.gn # Build configuration of test cases for the standard system 51f6603c60Sopenharmony_ci│ └── build_lite 52f6603c60Sopenharmony_ci│ └── BUILD.gn # Build configuration of test cases for mini and small systems 53f6603c60Sopenharmony_ci└── tools # Test tool code 54f6603c60Sopenharmony_ci``` 55f6603c60Sopenharmony_ci 56f6603c60Sopenharmony_ci## Constraints<a name="section119744591305"></a> 57f6603c60Sopenharmony_ci 58f6603c60Sopenharmony_ciTest cases for the mini system must be developed based on C, and those for the small system must be developed based on C++. 59f6603c60Sopenharmony_ci 60f6603c60Sopenharmony_ci## Usage Guidelines<a name="section137768191623"></a> 61f6603c60Sopenharmony_ci 62f6603c60Sopenharmony_ci**Table 1** Test case levels 63f6603c60Sopenharmony_ci 64f6603c60Sopenharmony_ci<a name="table12856113719456"></a> 65f6603c60Sopenharmony_ci<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>Level</p> 66f6603c60Sopenharmony_ci</th> 67f6603c60Sopenharmony_ci<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>Definition</p> 68f6603c60Sopenharmony_ci</th> 69f6603c60Sopenharmony_ci<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>Scope</p> 70f6603c60Sopenharmony_ci</th> 71f6603c60Sopenharmony_ci</tr> 72f6603c60Sopenharmony_ci</thead> 73f6603c60Sopenharmony_ci<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> 74f6603c60Sopenharmony_ci</td> 75f6603c60Sopenharmony_ci<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>Smoke</p> 76f6603c60Sopenharmony_ci</td> 77f6603c60Sopenharmony_ci<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>Verifies basic functionalities of key features and basic DFX attributes with the most common input. The pass result indicates that the features are runnable.</p> 78f6603c60Sopenharmony_ci</td> 79f6603c60Sopenharmony_ci</tr> 80f6603c60Sopenharmony_ci<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> 81f6603c60Sopenharmony_ci</td> 82f6603c60Sopenharmony_ci<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>Basic</p> 83f6603c60Sopenharmony_ci</td> 84f6603c60Sopenharmony_ci<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>Verifies basic functionalities of key features and basic DFX attributes with common input. The pass result indicates that the features are testable.</p> 85f6603c60Sopenharmony_ci</td> 86f6603c60Sopenharmony_ci</tr> 87f6603c60Sopenharmony_ci<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> 88f6603c60Sopenharmony_ci</td> 89f6603c60Sopenharmony_ci<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>Major</p> 90f6603c60Sopenharmony_ci</td> 91f6603c60Sopenharmony_ci<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>Verifies basic functionalities of key features and basic DFX attributes with common input and errors. The pass result indicates that the features are functional and ready for beta testing.</p> 92f6603c60Sopenharmony_ci</td> 93f6603c60Sopenharmony_ci</tr> 94f6603c60Sopenharmony_ci<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> 95f6603c60Sopenharmony_ci</td> 96f6603c60Sopenharmony_ci<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>Regular</p> 97f6603c60Sopenharmony_ci</td> 98f6603c60Sopenharmony_ci<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>Verifies functionalities of all key features, and all DFX attributes with common and uncommon input combinations or normal and abnormal preset conditions.</p> 99f6603c60Sopenharmony_ci</td> 100f6603c60Sopenharmony_ci</tr> 101f6603c60Sopenharmony_ci<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> 102f6603c60Sopenharmony_ci</td> 103f6603c60Sopenharmony_ci<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>Rare</p> 104f6603c60Sopenharmony_ci</td> 105f6603c60Sopenharmony_ci<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>Verifies functionalities of key features under extremely abnormal presets and uncommon input combinations.</p> 106f6603c60Sopenharmony_ci</td> 107f6603c60Sopenharmony_ci</tr> 108f6603c60Sopenharmony_ci</tbody> 109f6603c60Sopenharmony_ci</table> 110f6603c60Sopenharmony_ci 111f6603c60Sopenharmony_ci**Table 2** Test case granularities 112f6603c60Sopenharmony_ci 113f6603c60Sopenharmony_ci<a name="table1690733521014"></a> 114f6603c60Sopenharmony_ci<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>Test Scale</p> 115f6603c60Sopenharmony_ci</th> 116f6603c60Sopenharmony_ci<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>Test Objects</p> 117f6603c60Sopenharmony_ci</th> 118f6603c60Sopenharmony_ci<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>Test Environment</p> 119f6603c60Sopenharmony_ci</th> 120f6603c60Sopenharmony_ci</tr> 121f6603c60Sopenharmony_ci</thead> 122f6603c60Sopenharmony_ci<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> 123f6603c60Sopenharmony_ci</td> 124f6603c60Sopenharmony_ci<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>Service functionalities, all-scenario features, and mechanical power environment (MPE) and scenario-level DFX</p> 125f6603c60Sopenharmony_ci</td> 126f6603c60Sopenharmony_ci<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>Devices close to real devices</p> 127f6603c60Sopenharmony_ci</td> 128f6603c60Sopenharmony_ci</tr> 129f6603c60Sopenharmony_ci<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> 130f6603c60Sopenharmony_ci</td> 131f6603c60Sopenharmony_ci<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>Modules, subsystem functionalities after module integration, and DFX</p> 132f6603c60Sopenharmony_ci</td> 133f6603c60Sopenharmony_ci<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>Single device that is actually used. You can perform message simulation, but do not mock functions.</p> 134f6603c60Sopenharmony_ci</td> 135f6603c60Sopenharmony_ci</tr> 136f6603c60Sopenharmony_ci<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> 137f6603c60Sopenharmony_ci</td> 138f6603c60Sopenharmony_ci<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>Modules, classes, and functions</p> 139f6603c60Sopenharmony_ci</td> 140f6603c60Sopenharmony_ci<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>Local PC. Use a large number of mocks to replace dependencies with other modules.</p> 141f6603c60Sopenharmony_ci</td> 142f6603c60Sopenharmony_ci</tr> 143f6603c60Sopenharmony_ci</tbody> 144f6603c60Sopenharmony_ci</table> 145f6603c60Sopenharmony_ci 146f6603c60Sopenharmony_ci**Table 3** Test types 147f6603c60Sopenharmony_ci 148f6603c60Sopenharmony_ci<a name="table18811230124619"></a> 149f6603c60Sopenharmony_ci<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>Type</p> 150f6603c60Sopenharmony_ci</th> 151f6603c60Sopenharmony_ci<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>Definition</p> 152f6603c60Sopenharmony_ci</th> 153f6603c60Sopenharmony_ci</tr> 154f6603c60Sopenharmony_ci</thead> 155f6603c60Sopenharmony_ci<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> 156f6603c60Sopenharmony_ci</td> 157f6603c60Sopenharmony_ci<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>Tests the correctness of both service and platform functionalities provided by the tested object for end users or developers.</p> 158f6603c60Sopenharmony_ci</td> 159f6603c60Sopenharmony_ci</tr> 160f6603c60Sopenharmony_ci<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> 161f6603c60Sopenharmony_ci</td> 162f6603c60Sopenharmony_ci<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>Tests the processing capability of the tested object under specific preset conditions and load models. The processing capability is measured by the service volume that can be processed in a unit time, for example, call per second, frame per second, or event processing volume per second.</p> 163f6603c60Sopenharmony_ci</td> 164f6603c60Sopenharmony_ci</tr> 165f6603c60Sopenharmony_ci<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> 166f6603c60Sopenharmony_ci</td> 167f6603c60Sopenharmony_ci<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>Tests the power consumption of the tested object in a certain period of time under specific preset conditions and load models.</p> 168f6603c60Sopenharmony_ci</td> 169f6603c60Sopenharmony_ci</tr> 170f6603c60Sopenharmony_ci<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> 171f6603c60Sopenharmony_ci</td> 172f6603c60Sopenharmony_ci<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>Tests the service performance of the tested object under common and uncommon input conditions, or specified service volume pressure and long-term continuous running pressure. The test covers stability, pressure handling, fault injection, and Monkey test times.</p> 173f6603c60Sopenharmony_ci</td> 174f6603c60Sopenharmony_ci</tr> 175f6603c60Sopenharmony_ci<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> 176f6603c60Sopenharmony_ci</td> 177f6603c60Sopenharmony_ci<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><a name="ul112421652121513"></a><a name="ul112421652121513"></a><ul id="ul112421652121513"><li>Tests the capability of defending against security threats, including but not limited to unauthorized access, use, disclosure, damage, modification, and destruction, to ensure information confidentiality, integrity, and availability.</li><li>Tests the privacy protection capability to ensure that the collection, use, retention, disclosure, and disposal of users' private data comply with laws and regulations.</li><li>Tests the compliance with various security specifications, such as security design, security requirements, and security certification of the Ministry of Industry and Information Technology (MIIT).</li></ul> 178f6603c60Sopenharmony_ci</td> 179f6603c60Sopenharmony_ci</tr> 180f6603c60Sopenharmony_ci<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> 181f6603c60Sopenharmony_ci</td> 182f6603c60Sopenharmony_ci<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>Tests the internationalized data and localization capabilities of the tested object, including multi-language display, various input/output habits, time formats, and regional features, such as currency, time, and culture taboos.</p> 183f6603c60Sopenharmony_ci</td> 184f6603c60Sopenharmony_ci</tr> 185f6603c60Sopenharmony_ci<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> 186f6603c60Sopenharmony_ci</td> 187f6603c60Sopenharmony_ci<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><a name="ul186961827111612"></a><a name="ul186961827111612"></a><ul id="ul186961827111612"><li>Tests backward compatibility of an application with its own data, the forward and backward compatibility with the system, and the compatibility with different user data, such as audio file content of the player and smart SMS messages.</li><li>Tests system backward compatibility with its own data and the compatibility of common applications in the ecosystem.</li><li>Tests software compatibility with related hardware.</li></ul> 188f6603c60Sopenharmony_ci</td> 189f6603c60Sopenharmony_ci</tr> 190f6603c60Sopenharmony_ci<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> 191f6603c60Sopenharmony_ci</td> 192f6603c60Sopenharmony_ci<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>Tests user experience of the object in real user scenarios. All conclusions and comments should come from the users, which are all subjective evaluation in this case.</p> 193f6603c60Sopenharmony_ci</td> 194f6603c60Sopenharmony_ci</tr> 195f6603c60Sopenharmony_ci<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> 196f6603c60Sopenharmony_ci</td> 197f6603c60Sopenharmony_ci<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>Tests the compliance with industry and company-specific standards, protocols, and specifications. The standards here do not include any security standards that should be classified into the security test.</p> 198f6603c60Sopenharmony_ci</td> 199f6603c60Sopenharmony_ci</tr> 200f6603c60Sopenharmony_ci<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> 201f6603c60Sopenharmony_ci</td> 202f6603c60Sopenharmony_ci<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>Tests the safety property of the tested object to avoid possible hazards to personal safety, health, and the object itself.</p> 203f6603c60Sopenharmony_ci</td> 204f6603c60Sopenharmony_ci</tr> 205f6603c60Sopenharmony_ci<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> 206f6603c60Sopenharmony_ci</td> 207f6603c60Sopenharmony_ci<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>Tests the resilience property of the tested object to ensure that it can withstand and maintain the defined running status (including downgrading) when being attacked, and recover from and adapt defense to the attacks to approach mission assurance.</p> 208f6603c60Sopenharmony_ci</td> 209f6603c60Sopenharmony_ci</tr> 210f6603c60Sopenharmony_ci</tbody> 211f6603c60Sopenharmony_ci</table> 212f6603c60Sopenharmony_ci 213f6603c60Sopenharmony_ci## Test Case Development Guidelines<a name="section3695134065513"></a> 214f6603c60Sopenharmony_ci 215f6603c60Sopenharmony_ciYou should select the appropriate programming language and your target test framework to develop test cases. 216f6603c60Sopenharmony_ci 217f6603c60Sopenharmony_ci**Table 4** Test frameworks and test case languages for different systems 218f6603c60Sopenharmony_ci 219f6603c60Sopenharmony_ci<a name="table4418343171415"></a> 220f6603c60Sopenharmony_ci<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>System</p> 221f6603c60Sopenharmony_ci</th> 222f6603c60Sopenharmony_ci<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>Test Framework</p> 223f6603c60Sopenharmony_ci</th> 224f6603c60Sopenharmony_ci<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>Language</p> 225f6603c60Sopenharmony_ci</th> 226f6603c60Sopenharmony_ci</tr> 227f6603c60Sopenharmony_ci</thead> 228f6603c60Sopenharmony_ci<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>Mini</p> 229f6603c60Sopenharmony_ci</td> 230f6603c60Sopenharmony_ci<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> 231f6603c60Sopenharmony_ci</td> 232f6603c60Sopenharmony_ci<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> 233f6603c60Sopenharmony_ci</td> 234f6603c60Sopenharmony_ci</tr> 235f6603c60Sopenharmony_ci<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>Small</p> 236f6603c60Sopenharmony_ci</td> 237f6603c60Sopenharmony_ci<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> 238f6603c60Sopenharmony_ci</td> 239f6603c60Sopenharmony_ci<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> 240f6603c60Sopenharmony_ci</td> 241f6603c60Sopenharmony_ci</tr> 242f6603c60Sopenharmony_ci<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>Standard</p> 243f6603c60Sopenharmony_ci</td> 244f6603c60Sopenharmony_ci<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 and HCPPTest</p> 245f6603c60Sopenharmony_ci</td> 246f6603c60Sopenharmony_ci<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>JavaScript and C++</p> 247f6603c60Sopenharmony_ci</td> 248f6603c60Sopenharmony_ci</tr> 249f6603c60Sopenharmony_ci</tbody> 250f6603c60Sopenharmony_ci</table> 251f6603c60Sopenharmony_ci 252f6603c60Sopenharmony_ci### C-based Test Case Development and Compilation \(for the Mini System\)<a name="section198193336544"></a> 253f6603c60Sopenharmony_ci 254f6603c60Sopenharmony_ci**Developing test cases for the mini system** 255f6603c60Sopenharmony_ci 256f6603c60Sopenharmony_ciThe HCTest framework is used to support test cases developed with the C language. HCTest is enhanced and adapted based on the open-source test framework Unity. 257f6603c60Sopenharmony_ci 258f6603c60Sopenharmony_ci1. Access the **test/xts/acts** repository where the test cases will be stored. 259f6603c60Sopenharmony_ci 260f6603c60Sopenharmony_ci ``` 261f6603c60Sopenharmony_ci ├── acts 262f6603c60Sopenharmony_ci │ └──subsystem_lite 263f6603c60Sopenharmony_ci │ │ └── module_hal 264f6603c60Sopenharmony_ci │ │ │ └── BUILD.gn 265f6603c60Sopenharmony_ci │ │ │ └── src 266f6603c60Sopenharmony_ci │ └──build_lite 267f6603c60Sopenharmony_ci │ │ └── BUILD.gn 268f6603c60Sopenharmony_ci ``` 269f6603c60Sopenharmony_ci 270f6603c60Sopenharmony_ci2. Write the test case in the **src** directory. 271f6603c60Sopenharmony_ci 272f6603c60Sopenharmony_ci 1 Import the test framework header file. 273f6603c60Sopenharmony_ci 274f6603c60Sopenharmony_ci ``` 275f6603c60Sopenharmony_ci #include "hctest.h" 276f6603c60Sopenharmony_ci ``` 277f6603c60Sopenharmony_ci 278f6603c60Sopenharmony_ci 2. Use the **LITE\_TEST\_SUIT** macro to define names of the subsystem, module, and test suite. 279f6603c60Sopenharmony_ci 280f6603c60Sopenharmony_ci ``` 281f6603c60Sopenharmony_ci /** 282f6603c60Sopenharmony_ci * @brief Registers a test suite named IntTestSuite. 283f6603c60Sopenharmony_ci * @param test Subsystem name 284f6603c60Sopenharmony_ci * @param example Module name 285f6603c60Sopenharmony_ci * @param IntTestSuite Test suite name 286f6603c60Sopenharmony_ci */ 287f6603c60Sopenharmony_ci LITE_TEST_SUIT(test, example, IntTestSuite); 288f6603c60Sopenharmony_ci ``` 289f6603c60Sopenharmony_ci 290f6603c60Sopenharmony_ci 3. Define Setup and TearDown. 291f6603c60Sopenharmony_ci 292f6603c60Sopenharmony_ci Format: Test suite name+Setup, Test suite name+TearDown. 293f6603c60Sopenharmony_ci 294f6603c60Sopenharmony_ci The Setup and TearDown functions must exist, but function bodies can be empty. 295f6603c60Sopenharmony_ci 296f6603c60Sopenharmony_ci 4. Use the **LITE\_TEST\_CASE** macro to write the test case. 297f6603c60Sopenharmony_ci 298f6603c60Sopenharmony_ci Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\). 299f6603c60Sopenharmony_ci 300f6603c60Sopenharmony_ci ``` 301f6603c60Sopenharmony_ci LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1) 302f6603c60Sopenharmony_ci { 303f6603c60Sopenharmony_ci // Do something 304f6603c60Sopenharmony_ci }; 305f6603c60Sopenharmony_ci ``` 306f6603c60Sopenharmony_ci 307f6603c60Sopenharmony_ci 5. Use the **RUN\_TEST\_SUITE** macro to register the test suite. 308f6603c60Sopenharmony_ci 309f6603c60Sopenharmony_ci ``` 310f6603c60Sopenharmony_ci RUN_TEST_SUITE(IntTestSuite); 311f6603c60Sopenharmony_ci ``` 312f6603c60Sopenharmony_ci 313f6603c60Sopenharmony_ci3. Create the configuration file \(**BUILD.gn**\) of the test module. 314f6603c60Sopenharmony_ci 315f6603c60Sopenharmony_ci Create a **BUILD.gn** \(example\) build file in each test module directory. Specify the name of the built static library and its dependent header file and library in the build file. The format is as follows: 316f6603c60Sopenharmony_ci 317f6603c60Sopenharmony_ci ``` 318f6603c60Sopenharmony_ci import("//test/xts/tools/lite/build/suite_lite.gni") 319f6603c60Sopenharmony_ci hctest_suite("ActsDemoTest") { 320f6603c60Sopenharmony_ci suite_name = "acts" 321f6603c60Sopenharmony_ci sources = [ 322f6603c60Sopenharmony_ci "src/test_demo.c", 323f6603c60Sopenharmony_ci ] 324f6603c60Sopenharmony_ci include_dirs = [ ] 325f6603c60Sopenharmony_ci cflags = [ "-Wno-error" ] 326f6603c60Sopenharmony_ci } 327f6603c60Sopenharmony_ci ``` 328f6603c60Sopenharmony_ci 329f6603c60Sopenharmony_ci4. Add build options to the **BUILD.gn** file in the **acts** directory. 330f6603c60Sopenharmony_ci 331f6603c60Sopenharmony_ci You need to add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. 332f6603c60Sopenharmony_ci 333f6603c60Sopenharmony_ci ``` 334f6603c60Sopenharmony_ci lite_component("acts") { 335f6603c60Sopenharmony_ci ... 336f6603c60Sopenharmony_ci if(board_name == "liteos_m") { 337f6603c60Sopenharmony_ci features += [ 338f6603c60Sopenharmony_ci ... 339f6603c60Sopenharmony_ci "//xts/acts/subsystem_lite/module_hal:ActsDemoTest" 340f6603c60Sopenharmony_ci ] 341f6603c60Sopenharmony_ci } 342f6603c60Sopenharmony_ci } 343f6603c60Sopenharmony_ci ``` 344f6603c60Sopenharmony_ci 345f6603c60Sopenharmony_ci5. Run build commands. 346f6603c60Sopenharmony_ci 347f6603c60Sopenharmony_ci Test suites are built along with version build. The ACTS is built together with the debug version. 348f6603c60Sopenharmony_ci 349f6603c60Sopenharmony_ci > **NOTE:** 350f6603c60Sopenharmony_ci >The ACTS build middleware is a static library, which will be linked to the image. 351f6603c60Sopenharmony_ci 352f6603c60Sopenharmony_ci 353f6603c60Sopenharmony_ci### C-based Test Case Execution \(for the Mini System\)<a name="section13820233175418"></a> 354f6603c60Sopenharmony_ci 355f6603c60Sopenharmony_ci**Executing test cases for the mini system** 356f6603c60Sopenharmony_ci 357f6603c60Sopenharmony_ciBurn the image into the development board. 358f6603c60Sopenharmony_ci 359f6603c60Sopenharmony_ci**Executing the test** 360f6603c60Sopenharmony_ci 361f6603c60Sopenharmony_ci1. Use a serial port tool to log in to the development board and save information about the serial port. 362f6603c60Sopenharmony_ci2. Restart the device and view serial port logs. 363f6603c60Sopenharmony_ci 364f6603c60Sopenharmony_ci**Analyzing the test result** 365f6603c60Sopenharmony_ci 366f6603c60Sopenharmony_ciView the serial port logs, whose format is as follows: 367f6603c60Sopenharmony_ci 368f6603c60Sopenharmony_ciThe log for each test suite starts with **Start to run test suite:** and ends with **xx Tests xx Failures xx Ignored**. 369f6603c60Sopenharmony_ci 370f6603c60Sopenharmony_ci### C++-based Test Case Development and Compilation \(for Standard and Small Systems\)<a name="section3822123311540"></a> 371f6603c60Sopenharmony_ci 372f6603c60Sopenharmony_ci**Developing test cases for small-system devices** \(For examples of the standard system, go to the **global/i18n\_standard directory**.\) 373f6603c60Sopenharmony_ci 374f6603c60Sopenharmony_ciThe HCPPTest framework is enhanced and adapted based on the open-source framework Googletest. 375f6603c60Sopenharmony_ci 376f6603c60Sopenharmony_ci1. Access the **test/xts/acts** repository where the test cases will be stored. 377f6603c60Sopenharmony_ci 378f6603c60Sopenharmony_ci ``` 379f6603c60Sopenharmony_ci ├── acts 380f6603c60Sopenharmony_ci │ └──subsystem_lite 381f6603c60Sopenharmony_ci │ │ └── module_posix 382f6603c60Sopenharmony_ci │ │ │ └── BUILD.gn 383f6603c60Sopenharmony_ci │ │ │ └── src 384f6603c60Sopenharmony_ci │ └──build_lite 385f6603c60Sopenharmony_ci │ │ └── BUILD.gn 386f6603c60Sopenharmony_ci ``` 387f6603c60Sopenharmony_ci 388f6603c60Sopenharmony_ci2. Write the test case in the **src** directory. 389f6603c60Sopenharmony_ci 390f6603c60Sopenharmony_ci 1. Import the test framework header file. 391f6603c60Sopenharmony_ci 392f6603c60Sopenharmony_ci The following statement includes **gtest.h**. 393f6603c60Sopenharmony_ci 394f6603c60Sopenharmony_ci ``` 395f6603c60Sopenharmony_ci #include "gtest/gtest.h" 396f6603c60Sopenharmony_ci ``` 397f6603c60Sopenharmony_ci 398f6603c60Sopenharmony_ci 2. Define Setup and TearDown. 399f6603c60Sopenharmony_ci 400f6603c60Sopenharmony_ci ``` 401f6603c60Sopenharmony_ci using namespace std; 402f6603c60Sopenharmony_ci using namespace testing::ext; 403f6603c60Sopenharmony_ci class TestSuite: public testing::Test { 404f6603c60Sopenharmony_ci protected: 405f6603c60Sopenharmony_ci // Preset action of the test suite, which is executed before the first test case 406f6603c60Sopenharmony_ci static void SetUpTestCase(void){ 407f6603c60Sopenharmony_ci } 408f6603c60Sopenharmony_ci // Test suite cleanup action, which is executed after the last test case 409f6603c60Sopenharmony_ci static void TearDownTestCase(void){ 410f6603c60Sopenharmony_ci } 411f6603c60Sopenharmony_ci // Preset action of the test case 412f6603c60Sopenharmony_ci virtual void SetUp() 413f6603c60Sopenharmony_ci { 414f6603c60Sopenharmony_ci } 415f6603c60Sopenharmony_ci // Cleanup action of the test case 416f6603c60Sopenharmony_ci virtual void TearDown() 417f6603c60Sopenharmony_ci { 418f6603c60Sopenharmony_ci } 419f6603c60Sopenharmony_ci }; 420f6603c60Sopenharmony_ci ``` 421f6603c60Sopenharmony_ci 422f6603c60Sopenharmony_ci 3. Use the **HWTEST** or **HWTEST\_F** macro to write the test case. 423f6603c60Sopenharmony_ci 424f6603c60Sopenharmony_ci **HWTEST**: definition of common test cases, including the test suite name, test case name, and case annotation. 425f6603c60Sopenharmony_ci 426f6603c60Sopenharmony_ci **HWTEST\_F**: definition of SetUp and TearDown test cases, including the test suite name, test case name, and case annotation. 427f6603c60Sopenharmony_ci 428f6603c60Sopenharmony_ci Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\). 429f6603c60Sopenharmony_ci 430f6603c60Sopenharmony_ci ``` 431f6603c60Sopenharmony_ci HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) { 432f6603c60Sopenharmony_ci // Do something 433f6603c60Sopenharmony_ci } 434f6603c60Sopenharmony_ci ``` 435f6603c60Sopenharmony_ci 436f6603c60Sopenharmony_ci3. Create a configuration file \(**BUILD.gn**\) of the test module. 437f6603c60Sopenharmony_ci 438f6603c60Sopenharmony_ci Create a **BUILD.gn** build file in each test module directory. Specify the name of the built static library and its dependent header file and library in the build file. Each test module is independently built into a **.bin** executable file, which can be directly pushed to the development board for testing. 439f6603c60Sopenharmony_ci 440f6603c60Sopenharmony_ci Example: 441f6603c60Sopenharmony_ci 442f6603c60Sopenharmony_ci ``` 443f6603c60Sopenharmony_ci import("//test/xts/tools/lite/build/suite_lite.gni") 444f6603c60Sopenharmony_ci hcpptest_suite("ActsDemoTest") { 445f6603c60Sopenharmony_ci suite_name = "acts" 446f6603c60Sopenharmony_ci sources = [ 447f6603c60Sopenharmony_ci "src/TestDemo.cpp" 448f6603c60Sopenharmony_ci ] 449f6603c60Sopenharmony_ci 450f6603c60Sopenharmony_ci include_dirs = [ 451f6603c60Sopenharmony_ci "src", 452f6603c60Sopenharmony_ci ... 453f6603c60Sopenharmony_ci ] 454f6603c60Sopenharmony_ci deps = [ 455f6603c60Sopenharmony_ci ... 456f6603c60Sopenharmony_ci ] 457f6603c60Sopenharmony_ci cflags = [ "-Wno-error" ] 458f6603c60Sopenharmony_ci } 459f6603c60Sopenharmony_ci ``` 460f6603c60Sopenharmony_ci 461f6603c60Sopenharmony_ci4. Add build options to the **BUILD.gn** file in the **acts** directory. 462f6603c60Sopenharmony_ci 463f6603c60Sopenharmony_ci Add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. 464f6603c60Sopenharmony_ci 465f6603c60Sopenharmony_ci ``` 466f6603c60Sopenharmony_ci lite_component("acts") { 467f6603c60Sopenharmony_ci ... 468f6603c60Sopenharmony_ci else if(board_name == "liteos_a") { 469f6603c60Sopenharmony_ci features += [ 470f6603c60Sopenharmony_ci ... 471f6603c60Sopenharmony_ci "//xts/acts/subsystem_lite/module_posix:ActsDemoTest" 472f6603c60Sopenharmony_ci ] 473f6603c60Sopenharmony_ci } 474f6603c60Sopenharmony_ci } 475f6603c60Sopenharmony_ci ``` 476f6603c60Sopenharmony_ci 477f6603c60Sopenharmony_ci5. Run build commands. 478f6603c60Sopenharmony_ci 479f6603c60Sopenharmony_ci Test suites are built along with the version build. The ACTS is built together with the debug version. 480f6603c60Sopenharmony_ci 481f6603c60Sopenharmony_ci > **NOTE:** 482f6603c60Sopenharmony_ci >The ACTS for the small system is independently built to an executable file \(.bin\) and archived in the **suites\\acts** directory of the build result. 483f6603c60Sopenharmony_ci 484f6603c60Sopenharmony_ci 485f6603c60Sopenharmony_ci### C++-based Test Case Execution \(for Standard and Small Systems\)<a name="section128222336544"></a> 486f6603c60Sopenharmony_ci 487f6603c60Sopenharmony_ci**Executing test cases for the small system** 488f6603c60Sopenharmony_ci 489f6603c60Sopenharmony_ciCurrently, test cases are shared by the NFS and mounted to the development board for execution. 490f6603c60Sopenharmony_ci 491f6603c60Sopenharmony_ci**Setting up the environment** 492f6603c60Sopenharmony_ci 493f6603c60Sopenharmony_ci1. Use a network cable or wireless network to connect the development board to your PC. 494f6603c60Sopenharmony_ci2. Configure the IP address, subnet mask, and gateway for the development board. Ensure that the development board and the PC are in the same network segment. 495f6603c60Sopenharmony_ci3. Install and register the NFS server on the PC and start the NFS service. 496f6603c60Sopenharmony_ci4. Run the **mount** command for the development board to ensure that the development board can access NFS shared files on the PC. 497f6603c60Sopenharmony_ci 498f6603c60Sopenharmony_ci Format: **mount** _NFS server IP address_**:/**_NFS shared directory_ **/**_development board directory_ **nfs** 499f6603c60Sopenharmony_ci 500f6603c60Sopenharmony_ci Example: 501f6603c60Sopenharmony_ci 502f6603c60Sopenharmony_ci ``` 503f6603c60Sopenharmony_ci mount 192.168.1.10:/nfs /nfs nfs 504f6603c60Sopenharmony_ci ``` 505f6603c60Sopenharmony_ci 506f6603c60Sopenharmony_ci 507f6603c60Sopenharmony_ci**Executing test cases** 508f6603c60Sopenharmony_ci 509f6603c60Sopenharmony_ciExecute **ActsDemoTest.bin** to trigger test case execution, and analyze serial port logs generated after the execution is complete. 510f6603c60Sopenharmony_ci 511f6603c60Sopenharmony_ci### JavaScript-based Test Case Development \(for the Standard System\)<a name="section159801435165220"></a> 512f6603c60Sopenharmony_ci 513f6603c60Sopenharmony_ciThe HJSUnit framework is used to support automated test of OpenHarmony apps that are developed using the JavaScript language based on the JS application framework. 514f6603c60Sopenharmony_ci 515f6603c60Sopenharmony_ci**Basic syntax of test cases** 516f6603c60Sopenharmony_ci 517f6603c60Sopenharmony_ciThe test cases are developed with the JavaScript language and must meet the programming specifications of the language. 518f6603c60Sopenharmony_ci 519f6603c60Sopenharmony_ci**Table 5** 520f6603c60Sopenharmony_ci 521f6603c60Sopenharmony_ci<a name="table13980103565212"></a> 522f6603c60Sopenharmony_ci<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>Syntax</p> 523f6603c60Sopenharmony_ci</th> 524f6603c60Sopenharmony_ci<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>Description</p> 525f6603c60Sopenharmony_ci</th> 526f6603c60Sopenharmony_ci<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>Mandatory</p> 527f6603c60Sopenharmony_ci</th> 528f6603c60Sopenharmony_ci</tr> 529f6603c60Sopenharmony_ci</thead> 530f6603c60Sopenharmony_ci<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> 531f6603c60Sopenharmony_ci</td> 532f6603c60Sopenharmony_ci<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>Presets a test-suite-level action executed only once before all test cases are executed. You can pass the action function as the only parameter.</p> 533f6603c60Sopenharmony_ci</td> 534f6603c60Sopenharmony_ci<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>No</p> 535f6603c60Sopenharmony_ci</td> 536f6603c60Sopenharmony_ci</tr> 537f6603c60Sopenharmony_ci<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> 538f6603c60Sopenharmony_ci</td> 539f6603c60Sopenharmony_ci<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>Presets a test-suite-level clear action executed only once after all test cases are executed. You can pass the clear function as the only parameter.</p> 540f6603c60Sopenharmony_ci</td> 541f6603c60Sopenharmony_ci<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>No</p> 542f6603c60Sopenharmony_ci</td> 543f6603c60Sopenharmony_ci</tr> 544f6603c60Sopenharmony_ci<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> 545f6603c60Sopenharmony_ci</td> 546f6603c60Sopenharmony_ci<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>Presets a test-case-level action executed before each test case is executed. The number of execution times is the same as the number of test cases defined by <strong id="b32523248388"><a name="b32523248388"></a><a name="b32523248388"></a>it</strong>. You can pass the action function as the only parameter.</p> 547f6603c60Sopenharmony_ci</td> 548f6603c60Sopenharmony_ci<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>No</p> 549f6603c60Sopenharmony_ci</td> 550f6603c60Sopenharmony_ci</tr> 551f6603c60Sopenharmony_ci<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> 552f6603c60Sopenharmony_ci</td> 553f6603c60Sopenharmony_ci<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>Presets a test-case-level clear action executed after each test case is executed. The number of execution times is the same as the number of test cases defined by <strong id="b10590142313399"><a name="b10590142313399"></a><a name="b10590142313399"></a>it</strong>. You can pass the clear function as the only parameter.</p> 554f6603c60Sopenharmony_ci</td> 555f6603c60Sopenharmony_ci<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>No</p> 556f6603c60Sopenharmony_ci</td> 557f6603c60Sopenharmony_ci</tr> 558f6603c60Sopenharmony_ci<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> 559f6603c60Sopenharmony_ci</td> 560f6603c60Sopenharmony_ci<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>Defines a test suite. You can pass two parameters: test suite name and test suite function. The <strong id="b7320205019400"><a name="b7320205019400"></a><a name="b7320205019400"></a>describe</strong> statement supports nesting. You can use <strong id="b138214222410"><a name="b138214222410"></a><a name="b138214222410"></a>beforeall</strong>, <strong id="b18677102314115"><a name="b18677102314115"></a><a name="b18677102314115"></a>beforeEach</strong>, <strong id="b1353142514113"><a name="b1353142514113"></a><a name="b1353142514113"></a>afterEach</strong>, and <strong id="b131041629204111"><a name="b131041629204111"></a><a name="b131041629204111"></a>afterAll</strong> in each <strong id="b590433484116"><a name="b590433484116"></a><a name="b590433484116"></a>describe</strong> statement.</p> 561f6603c60Sopenharmony_ci</td> 562f6603c60Sopenharmony_ci<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>Yes</p> 563f6603c60Sopenharmony_ci</td> 564f6603c60Sopenharmony_ci</tr> 565f6603c60Sopenharmony_ci<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> 566f6603c60Sopenharmony_ci</td> 567f6603c60Sopenharmony_ci<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>Defines a test case. You can pass three parameters: test case name, filter parameter, and test case function.</p> 568f6603c60Sopenharmony_ci<p id="p5205769588"><a name="p5205769588"></a><a name="p5205769588"></a>Usage of the filter parameter:</p> 569f6603c60Sopenharmony_ci<p id="p1545919528618"><a name="p1545919528618"></a><a name="p1545919528618"></a>The value of the filter parameter is a 32-bit integer. Setting different bits to <strong id="b045919521765"><a name="b045919521765"></a><a name="b045919521765"></a>1</strong> means different configurations:</p> 570f6603c60Sopenharmony_ci<a name="ul6932113319395"></a><a name="ul6932113319395"></a><ul id="ul6932113319395"><li>bit 0: whether the filter parameter takes effect. <strong id="b1193293318395"><a name="b1193293318395"></a><a name="b1193293318395"></a>1</strong> means that the test case is used for the function test and other settings of the parameter do not take effect.</li><li>Bits 0-10: test case categories</li><li>Bits 16-18: test case scales</li><li>Bits 24-28: test levels</li></ul> 571f6603c60Sopenharmony_ci<p id="p7965165151011"><a name="p7965165151011"></a><a name="p7965165151011"></a><strong id="b15148755145114"><a name="b15148755145114"></a><a name="b15148755145114"></a>Test case categories</strong>: Bits 0-10 indicate FUNCTION (function test), PERFORMANCE (performance test), POWER (power consumption test), RELIABILITY (reliability test), SECURITY (security compliance test), GLOBAL (integrity test), COMPATIBILITY (compatibility test), USER (user test), STANDARD (standard test), SAFETY (security feature test), and RESILIENCE (resilience test), respectively.</p> 572f6603c60Sopenharmony_ci<p id="p199651555102"><a name="p199651555102"></a><a name="p199651555102"></a><strong id="b135908568519"><a name="b135908568519"></a><a name="b135908568519"></a>Test case scales</strong>: Bits 16-18 indicate SMALL (small-scale test), MEDIUM (medium-scale test), and LARGE (large-scale test), respectively.</p> 573f6603c60Sopenharmony_ci<p id="p296545151020"><a name="p296545151020"></a><a name="p296545151020"></a><strong id="b12181058125111"><a name="b12181058125111"></a><a name="b12181058125111"></a>Test levels</strong>: Bits 24-28 indicate LEVEL0 (level-0 test), LEVEL1 (level-1 test), LEVEL2 (level-2 test), LEVEL3 (level-3 test), and LEVEL4 (level-4 test), respectively.</p> 574f6603c60Sopenharmony_ci</td> 575f6603c60Sopenharmony_ci<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>Yes</p> 576f6603c60Sopenharmony_ci</td> 577f6603c60Sopenharmony_ci</tr> 578f6603c60Sopenharmony_ci</tbody> 579f6603c60Sopenharmony_ci</table> 580f6603c60Sopenharmony_ci 581f6603c60Sopenharmony_ciUse the standard syntax of Jasmine to write test cases. The ES6 specification is supported. 582f6603c60Sopenharmony_ci 583f6603c60Sopenharmony_ci1. Store the test cases in the **entry/src/main/js/test** directory, whose structure is as follows: 584f6603c60Sopenharmony_ci 585f6603c60Sopenharmony_ci ``` 586f6603c60Sopenharmony_ci ├── BUILD.gn 587f6603c60Sopenharmony_ci │ └──entry 588f6603c60Sopenharmony_ci │ │ └──src 589f6603c60Sopenharmony_ci │ │ │ └──main 590f6603c60Sopenharmony_ci │ │ │ │ └──js 591f6603c60Sopenharmony_ci │ │ │ │ │ └──default 592f6603c60Sopenharmony_ci │ │ │ │ │ │ └──pages 593f6603c60Sopenharmony_ci │ │ │ │ │ │ │ └──index 594f6603c60Sopenharmony_ci │ │ │ │ │ │ │ │ └──index.js # Entry file 595f6603c60Sopenharmony_ci │ │ │ │ │ └──test # Test code 596f6603c60Sopenharmony_ci │ │ │ └── resources # HAP resources 597f6603c60Sopenharmony_ci │ │ │ └── config.json # HAP configuration file 598f6603c60Sopenharmony_ci ``` 599f6603c60Sopenharmony_ci 600f6603c60Sopenharmony_ci2. Start the JS test framework and load test cases. The following is an example for **index.js**. 601f6603c60Sopenharmony_ci 602f6603c60Sopenharmony_ci ``` 603f6603c60Sopenharmony_ci // Start the JS test framework and load test cases. 604f6603c60Sopenharmony_ci import {Core, ExpectExtend} from 'deccjsunit/index' 605f6603c60Sopenharmony_ci 606f6603c60Sopenharmony_ci export default { 607f6603c60Sopenharmony_ci data: { 608f6603c60Sopenharmony_ci title: "" 609f6603c60Sopenharmony_ci }, 610f6603c60Sopenharmony_ci onInit() { 611f6603c60Sopenharmony_ci this.title = this.$t('strings.world'); 612f6603c60Sopenharmony_ci }, 613f6603c60Sopenharmony_ci onShow() { 614f6603c60Sopenharmony_ci console.info('onShow finish') 615f6603c60Sopenharmony_ci const core = Core.getInstance() 616f6603c60Sopenharmony_ci const expectExtend = new ExpectExtend({ 617f6603c60Sopenharmony_ci 'id': 'extend' 618f6603c60Sopenharmony_ci }) 619f6603c60Sopenharmony_ci core.addService('expect', expectExtend) 620f6603c60Sopenharmony_ci core.init() 621f6603c60Sopenharmony_ci const configService = core.getDefaultService('config') 622f6603c60Sopenharmony_ci configService.setConfig(this) 623f6603c60Sopenharmony_ci require('../../../test/List.test') 624f6603c60Sopenharmony_ci core.execute() 625f6603c60Sopenharmony_ci }, 626f6603c60Sopenharmony_ci onReady() { 627f6603c60Sopenharmony_ci }, 628f6603c60Sopenharmony_ci } 629f6603c60Sopenharmony_ci ``` 630f6603c60Sopenharmony_ci 631f6603c60Sopenharmony_ci3. Write a unit test case by referring to the following example: 632f6603c60Sopenharmony_ci 633f6603c60Sopenharmony_ci ``` 634f6603c60Sopenharmony_ci // Use HJSUnit to perform the unit test. 635f6603c60Sopenharmony_ci describe('appInfoTest', function () { 636f6603c60Sopenharmony_ci it('app_info_test_001', 0, function () { 637f6603c60Sopenharmony_ci var info = app.getInfo() 638f6603c60Sopenharmony_ci expect(info.versionName).assertEqual('1.0') 639f6603c60Sopenharmony_ci expect(info.versionCode).assertEqual('3') 640f6603c60Sopenharmony_ci }) 641f6603c60Sopenharmony_ci }) 642f6603c60Sopenharmony_ci ``` 643f6603c60Sopenharmony_ci 644f6603c60Sopenharmony_ci 645f6603c60Sopenharmony_ci### JavaScript-based Test Case Packaging \(for the Standard System\)<a name="section445519106559"></a> 646f6603c60Sopenharmony_ci 647f6603c60Sopenharmony_ciFor details about how to build a HAP, see the JS application development guide of the standard system [Building and Creating HAPs](https://developer.harmonyos.com/en/docs/documentation/doc-guides/build_overview-0000001055075201). 648f6603c60Sopenharmony_ci 649