• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Test Case Development
2OpenHarmony provides a comprehensive auto-test framework for designing test cases. Detecting defects in the development process can improve code quality.
3
4This document describes how to use the OpenHarmony test framework.
5## Setting Up the Environment
6The test framework depends on the Python running environment. Before using the test framework, set up the environment as follows:
7 - [Setting Up the Environment](subsys-testguide-envbuild.md)
8 - [Obtaining Source Code](../get-code/sourcecode-acquire.md)
9
10
11## Directory Structure
12The directory structure of the test framework is as follows:
13```
14test # Test subsystem
15├── developertest  # Developer test module
16│   ├── aw  # Static library of the test framework
17│   ├── config  # Test framework configuration
18│   │   │ ...
19│   │   └── user_config.xml  # User configuration
20│   ├── examples  # Examples of test cases
21│   ├── src  # Source code of the test framework
22│   ├── third_party  # Adaptation code for third-party components on which the test framework depends
23│   ├── reports  # Test reports
24│   ├── BUILD.gn  # Build entry of the test framework
25│   ├── start.bat  # Test entry for Windows
26│   └── start.sh  # Test entry for Linux
27└── xdevice  # Modules on which the test framework depends
28```
29## Writing Test Cases
30###  Designing the Test Case Directory
31Design the test case directory as follows:
32```
33subsystem # Subsystem
34├── partA  # Part A
35│   ├── moduleA  # Module A
36│   │   ├── include
37│   │   ├── src  # Service code
38│   │   └── test  # Test directory
39│   │       ├── unittest  # Unit test
40│   │       │   ├── common  # Common test cases
41│   │       │   │   ├── BUILD.gn  # Build file of test cases
42│   │       │   │   └── testA_test.cpp  # Source code of unit test cases
43│   │       │   ├── phone  # Test cases for mobile phones
44│   │       │   ├── ivi  # Test cases for head units
45│   │       │   └── liteos-a  # Test cases for the IP cameras that use the LiteOS kernel
46│   │       ├── moduletest  # Module test
47│   │       ...
48│   │
49│   ├── moduleB  # Module B
50│   ├── test
51│   │   └── resource  # Dependency resources
52│   │       ├── moduleA  # Module A
53│   │       │   ├── ohos_test.xml # Resource configuration file
54│   │       ... └── 1.txt  # Resources
55│   │
56│   ├── ohos_build  # Build entry configuration
57│   ...
5859...
60```
61> **Note:** Test cases are classified into common test cases and device-specific test cases. You are advised to place common test cases in the **common** directory and device-specific test cases in the directories of the related devices.
62
63###  Writing Test Cases
64This test framework supports test cases written in multiple programming languages and provides different templates for different languages.
65
66**C++ Test Case Example**
67
68- Naming rules for source files
69
70    The source file name of test cases must be the same as that of the test suite. The file names must use lowercase letters and in the [Function]\_[Sub-function]\_**test** format. More specific sub-functions can be added as required.
71Example:
72    ```
73    calculator_sub_test.cpp
74    ```
75
76- Test case example
77    ```
78    /*
79     * Copyright (c) 2021 XXXX Device Co., Ltd.
80     * Licensed under the Apache License, Version 2.0 (the "License");
81     * you may not use this file except in compliance with the License.
82     * You may obtain a copy of the License at
83     *
84     *     http://www.apache.org/licenses/LICENSE-2.0
85     *
86     * Unless required by applicable law or agreed to in writing, software
87     * distributed under the License is distributed on an "AS IS" BASIS,
88     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
89     * See the License for the specific language governing permissions and
90     * limitations under the License.
91     */
92
93    #include "calculator.h"
94    #include <gtest/gtest.h>
95
96    using namespace testing::ext;
97
98    class CalculatorSubTest : public testing::Test {
99    public:
100        static void SetUpTestCase(void);
101        static void TearDownTestCase(void);
102        void SetUp();
103        void TearDown();
104    };
105
106    void CalculatorSubTest::SetUpTestCase(void)
107    {
108        // Set a setup function, which will be called before all test cases.
109    }
110
111    void CalculatorSubTest::TearDownTestCase(void)
112    {
113        // Set a teardown function, which will be called after all test cases.
114    }
115
116    void CalculatorSubTest::SetUp(void)
117    {
118        // Set a setup function, which will be called before each test case.
119    }
120
121    void CalculatorSubTest::TearDown(void)
122    {
123        // Set a teardown function, which will be called after each test case.
124    }
125
126    /**
127     * @tc.name: integer_sub_001
128     * @tc.desc: Verify the sub-function.
129     * @tc.type: FUNC
130     * @tc.require: Issue Number
131     */
132    HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1)
133    {
134        // Step 1 Call the function to obtain the result.
135        int actual = Sub(4, 0);
136
137        // Step 2 Use an assertion to compare the obtained result with the expected result.
138        EXPECT_EQ(4, actual);
139    }
140    ```
141    The procedure is as follows:
142    1. Add comment information to the test case file header.
143	    ```
144    	/*
145    	 * Copyright (c) 2021 XXXX Device Co., Ltd.
146    	 * Licensed under the Apache License, Version 2.0 (the "License");
147    	 * you may not use this file except in compliance with the License.
148    	 * You may obtain a copy of the License at
149    	 *
150    	 *     http://www.apache.org/licenses/LICENSE-2.0
151    	 *
152    	 * Unless required by applicable law or agreed to in writing, software
153    	 * distributed under the License is distributed on an "AS IS" BASIS,
154    	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
155    	 * See the License for the specific language governing permissions and
156    	 * limitations under the License.
157    	 */
158    	```
159    2. Add the test framework header file and namespace.
160	    ```
161    	#include <gtest/gtest.h>
162
163    	using namespace testing::ext;
164    	```
165    3. Add the header file of the test class.
166	    ```
167    	#include "calculator.h"
168    	```
169    4. Define the test suite (test class).
170	    ```
171    	class CalculatorSubTest : public testing::Test {
172    	public:
173    	    static void SetUpTestCase(void);
174    	    static void TearDownTestCase(void);
175    	    void SetUp();
176    	    void TearDown();
177    	};
178
179    	void CalculatorSubTest::SetUpTestCase(void)
180    	{
181    	    // Set a setup function, which will be called before all test cases.
182    	}
183
184    	void CalculatorSubTest::TearDownTestCase(void)
185    	{
186    	    // Set a teardown function, which will be called after all test cases.
187    	}
188
189    	void CalculatorSubTest::SetUp(void)
190    	{
191    	    // Set a setup function, which will be called before each test case.
192    	}
193
194    	void CalculatorSubTest::TearDown(void)
195    	{
196    	    // Set a teardown function, which will be called after each test case.
197    	}
198    	```
199	    > **Note**: When defining a test suite, ensure that the test suite name is the same as the target to build and uses the upper camel case style.
200
201    5. Add implementation of the test cases, including test case comments and logic.
202	    ```
203    	/**
204    	 * @tc.name: integer_sub_001
205    	 * @tc.desc: Verify the sub-function.
206    	 * @tc.type: FUNC
207    	 * @tc.require: Issue Number
208    	 */
209    	HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1)
210    	{
211    	    // Step 1 Call the function to obtain the test result.
212    	    int actual = Sub(4, 0);
213
214    	    // Step 2 Use an assertion to compare the obtained result with the expected result.
215    	    EXPECT_EQ(4, actual);
216    	}
217    	```
218	    The following test case templates are provided for your reference.
219
220	    |      Type|    Description|
221    	| ------------| ------------|
222    	| HWTEST(A,B,C)| Use this template if the test case execution does not depend on setup or teardown.|
223    	| HWTEST_F(A,B,C)| Use this template if the test case execution (excluding parameters) depends on setup and teardown.|
224    	| HWTEST_P(A,B,C)| Use this template if the test case execution (including parameters) depends on setup and teardown.|
225
226	    In the template names:
227	- *A* indicates the test suite name.
228	- *B* indicates the test case name, which is in the *Function*\_*No.* format. The *No.* is a three-digit number starting from **001**.
229	- *C* indicates the test case level. There are five test case levels: guard-control level 0 and non-guard-control level 1 to level 4. Of levels 1 to 4, a smaller value indicates a more important function verified by the test case.
230
231	    **Note**:
232	- The expected result of each test case must have an assertion.
233	- The test case level must be specified.
234	- It is recommended that the test be implemented step by step according to the template.
235	- The comment must contain the test case name, description, type, and requirement number, which are in the @tc.*xxx*: *value* format. The test case type @**tc.type** can be any of the following:
236
237	    | Test Case Type|Code|
238    	| ------------|------------|
239    	|Function test|FUNC|
240        |Performance test|PERF|
241        |Reliability test|RELI|
242        |Security test|SECU|
243        |Fuzz test|FUZZ|
244
245
246**JavaScript Test Case Example**
247
248- Naming rules for source files
249
250    The source file name of a test case must be in the [Function]\[Sub-function]Test format, and each part must use the upper camel case style. More specific sub-functions can be added as required.
251Example:
252    ```
253    AppInfoTest.js
254    ```
255
256- Test case example
257    ```
258    /*
259     * Copyright (C) 2021 XXXX Device Co., Ltd.
260     * Licensed under the Apache License, Version 2.0 (the "License");
261     * you may not use this file except in compliance with the License.
262     * You may obtain a copy of the License at
263     *
264     *     http://www.apache.org/licenses/LICENSE-2.0
265     *
266     * Unless required by applicable law or agreed to in writing, software
267     * distributed under the License is distributed on an "AS IS" BASIS,
268     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
269     * See the License for the specific language governing permissions and
270     * limitations under the License.
271     */
272    import app from '@system.app'
273
274    import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
275
276    describe("AppInfoTest", function () {
277        beforeAll(function() {
278            // Set a setup function, which will be called before all test cases.
279             console.info('beforeAll caled')
280        })
281
282        afterAll(function() {
283             // Set a teardown function, which will be called after all test cases.
284             console.info('afterAll caled')
285        })
286
287        beforeEach(function() {
288            // Set a setup function, which will be called before each test case.
289             console.info('beforeEach caled')
290        })
291
292        afterEach(function() {
293            // Set a teardown function, which will be called after each test case.
294             console.info('afterEach caled')
295        })
296
297        /*
298         * @tc.name:appInfoTest001
299         * @tc.desc:verify app info is not null
300         * @tc.type: FUNC
301         * @tc.require: Issue Number
302         */
303        it("appInfoTest001", 0, function () {
304            // Step 1 Call the function to obtain the test result.
305            var info = app.getInfo()
306
307            // Step 2 Use an assertion to compare the obtained result with the expected result.
308            expect(info != null).assertEqual(true)
309        })
310    })
311    ```
312    The procedure is as follows:
313    1. Add comment information to the test case file header.
314	    ```
315    	/*
316    	 * Copyright (C) 2021 XXXX Device Co., Ltd.
317    	 * Licensed under the Apache License, Version 2.0 (the "License");
318    	 * you may not use this file except in compliance with the License.
319    	 * You may obtain a copy of the License at
320    	 *
321    	 *     http://www.apache.org/licenses/LICENSE-2.0
322    	 *
323    	 * Unless required by applicable law or agreed to in writing, software
324    	 * distributed under the License is distributed on an "AS IS" BASIS,
325    	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
326    	 * See the License for the specific language governing permissions and
327    	 * limitations under the License.
328    	 */
329    	```
330    2. Import the APIs and JSUnit test library to test.
331	    ```
332    	import app from '@system.app'
333
334    	import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
335    	```
336    3. Define the test suite (test class).
337	    ```
338    	describe("AppInfoTest", function () {
339    	    beforeAll(function() {
340    	        // Set a setup function, which will be called before all test cases.
341    	         console.info('beforeAll caled')
342    	    })
343
344    	    afterAll(function() {
345    	         // Set a teardown function, which will be called after all test cases.
346    	         console.info('afterAll caled')
347    	    })
348
349    	    beforeEach(function() {
350    	        // Set a setup function, which will be called before each test case.
351    	         console.info('beforeEach caled')
352    	    })
353
354    	    afterEach(function() {
355    	        // Set a teardown function, which will be called after each test case.
356    	         console.info('afterEach caled')
357    	    })
358    	```
359    4. Add implementation of the test cases.
360	    ```
361    	/*
362    	 * @tc.name:appInfoTest001
363    	 * @tc.desc:verify app info is not null
364    	 * @tc.type: FUNC
365    	 * @tc.require: Issue Number
366    	 */
367    	 it("appInfoTest001", 0, function () {
368    	    // Step 1 Call the function to obtain the test result.
369            var info = app.getInfo()
370
371            // Step 2 Use an assertion to compare the obtained result with the expected result.
372            expect(info != null).assertEqual(true)
373    	 })
374    	```
375
376### Writing the Build File for Test Cases
377When a test case is executed, the test framework searches for the build file of the test case in the test case directory and builds the test case located. The following describes how to write build files (GN files) in different programming languages.
378
379#### Writing Build Files for Test Cases
380The following provides templates for different languages for your reference.
381
382- **Test case build file example (C++)**
383    ```
384    # Copyright (c) 2021 XXXX Device Co., Ltd.
385
386    import("//build/test.gni")
387
388    module_output_path = "subsystem_examples/calculator"
389
390    config("module_private_config") {
391      visibility = [ ":*" ]
392
393      include_dirs = [ "../../../include" ]
394    }
395
396    ohos_unittest("CalculatorSubTest") {
397      module_out_path = module_output_path
398
399      sources = [
400        "../../../include/calculator.h",
401        "../../../src/calculator.cpp",
402      ]
403
404      sources += [ "calculator_sub_test.cpp" ]
405
406      configs = [ ":module_private_config" ]
407
408      deps = [ "//third_party/googletest:gtest_main" ]
409    }
410
411    group("unittest") {
412      testonly = true
413      deps = [":CalculatorSubTest"]
414    }
415    ```
416    The procedure is as follows:
417
418    1. Add comment information for the file header.
419	    ```
420    	# Copyright (c) 2021 XXXX Device Co., Ltd.
421    	```
422    2. Import the build template.
423	    ```
424    	import("//build/test.gni")
425    	```
426    3. Specify the file output path.
427    	```
428    	module_output_path = "subsystem_examples/calculator"
429    	```
430    	> **Note**: The output path is ***Part name*/*Module name***.
431
432    4. Configure the directories for dependencies.
433
434    	```
435    	config("module_private_config") {
436    	  visibility = [ ":*" ]
437
438    	  include_dirs = [ "../../../include" ]
439    	}
440    	```
441    	> **Note**: Generally, the dependency directories are configured here and directly referenced in the build script of the test case.
442
443    5. Set the output build file for the test cases.
444
445    	```
446    	ohos_unittest("CalculatorSubTest") {
447    	}
448    	```
449    6. Write the build script (add the source file, configuration, and dependencies) for the test cases.
450    	```
451    	ohos_unittest("CalculatorSubTest") {
452    	  module_out_path = module_output_path
453    	  sources = [
454    	    "../../../include/calculator.h",
455    	    "../../../src/calculator.cpp",
456    	    "../../../test/calculator_sub_test.cpp"
457    	  ]
458    	  sources += [ "calculator_sub_test.cpp" ]
459    	  configs = [ ":module_private_config" ]
460    	  deps = [ "//third_party/googletest:gtest_main" ]
461    	}
462    	```
463
464	    > **Note:** Set the test type based on actual requirements. The following test types are available:
465    	> - **ohos_unittest**: unit test
466    	> - **ohos_moduletest**: module test
467    	> - **ohos_systemtest**: system test
468    	> - **ohos_performancetest**: performance test
469    	> - **ohos_securitytest**: security test
470    	> - **ohos_reliabilitytest**: reliability test
471    	> - **ohos_distributedtest**: distributed test
472
473    7. Group the test case files by test type.
474
475    	```
476    	group("unittest") {
477    	  testonly = true
478    	  deps = [":CalculatorSubTest"]
479    	}
480    	```
481    	> **Note**: Grouping test cases by test type allows you to execute a specific type of test cases when required.
482
483- **Test case build file example (JavaScript)**
484
485    ```
486    # Copyright (C) 2021 XXXX Device Co., Ltd.
487
488    import("//build/test.gni")
489
490    module_output_path = "subsystem_examples/app_info"
491
492    ohos_js_unittest("GetAppInfoJsTest") {
493      module_out_path = module_output_path
494
495      hap_profile = "./config.json"
496      certificate_profile = "//test/developertest/signature/openharmony_sx.p7b"
497    }
498
499    group("unittest") {
500      testonly = true
501      deps = [ ":GetAppInfoJsTest" ]
502    }
503    ```
504
505    The procedure is as follows:
506
507    1. Add comment information for the file header.
508
509    	```
510    	# Copyright (C) 2021 XXXX Device Co., Ltd.
511    	```
512    2. Import the build template.
513
514    	```
515    	import("//build/test.gni")
516    	```
517    3. Specify the file output path.
518
519    	```
520    	module_output_path = "subsystem_examples/app_info"
521    	```
522    	> **Note**: The output path is ***Part name*/*Module name***.
523
524    4. Set the output build file for the test cases.
525
526    	```
527    	ohos_js_unittest("GetAppInfoJsTest") {
528    	}
529    	```
530    	> **Note:**
531    	>- Use the **ohos\_js\_unittest** template to define the JavaScript test suite. Pay attention to the difference between JavaScript and C++.
532    	>- The file generated for the JavaScript test suite must be in .hap format and named after the test suite name defined here. The test suite name must end with **JsTest**.
533
534    5. Configure the **config.json** file and signature file, which are mandatory.
535
536    	```
537    	ohos_js_unittest("GetAppInfoJsTest") {
538    	  module_out_path = module_output_path
539
540    	  hap_profile = "./config.json"
541    	  certificate_profile = "//test/developertest/signature/openharmony_sx.p7b"
542    	}
543    	```
544    	**config.json** is the configuration file required for HAP build. You need to set **target** based on the tested SDK version. Default values can be retained for other items. The following is an example:
545
546    	```
547    	{
548    	  "app": {
549    	    "bundleName": "com.example.myapplication",
550    	    "vendor": "example",
551    	    "version": {
552    	      "code": 1,
553    	      "name": "1.0"
554    	    },
555    	    "apiVersion": {
556    	           "compatible": 4,
557    	         "target": 5 // Set it based on the tested SDK version. In this example, SDK5 is used.
558    	    }
559    	  },
560    	  "deviceConfig": {},
561    	  "module": {
562    	    "package": "com.example.myapplication",
563    	    "name": ".MyApplication",
564    	    "deviceType": [
565    	      "phone"
566    	    ],
567    	    "distro": {
568    	      "deliveryWithInstall": true,
569    	      "moduleName": "entry",
570    	      "moduleType": "entry"
571    	    },
572    	    "abilities": [
573    	      {
574    	      "skills": [
575    	          {
576    	            "entities": [
577    	              "entity.system.home"
578    	            ],
579    	            "actions": [
580    	              "action.system.home"
581    	            ]
582    	          }
583    	        ],
584    	        "name": "com.example.myapplication.MainAbility",
585    	        "icon": "$media:icon",
586    	        "description": "$string:mainability_description",
587    	        "label": "MyApplication",
588    	        "type": "page",
589    	        "launchType": "standard"
590    	      }
591    	    ],
592    	    "js": [
593    	      {
594    	        "pages": [
595    	          "pages/index/index"
596    	        ],
597    	        "name": "default",
598    	          "window": {
599    	             "designWidth": 720,
600    	             "autoDesignWidth": false
601    	          }
602    	        }
603    	      ]
604    	    }
605    	  }
606    	```
607    6. Group the test case files by test type.
608    	```
609    	group("unittest") {
610    	  testonly = true
611    	  deps = [ ":GetAppInfoJsTest" ]
612    	}
613    	```
614    	> **Note**: Grouping test cases by test type allows you to execute a specific type of test cases when required.
615
616#### Configuring ohos.build
617
618Configure the part build file to associate with specific test cases.
619```
620"partA": {
621    "module_list": [
622
623    ],
624    "inner_list": [
625
626    ],
627    "system_kits": [
628
629    ],
630    "test_list": [
631      "//system/subsystem/partA/calculator/test:unittest"  // Configure test under calculator.
632    ]
633 }
634```
635> **Note**: **test_list** contains the test cases of the corresponding module.
636
637### Configuring Test Case Resources
638Test case resources include external file resources, such as image files, video files, and third-party libraries, required for test case execution.
639
640Perform the following steps:
6411. Create the **resource** directory in the **test** directory of the part, and create a directory for the module in the **resource** directory to store resource files of the module.
642
6432. In the module directory under **resource**, create the **ohos_test.xml** file in the following format:
644	```
645	<?xml version="1.0" encoding="UTF-8"?>
646	<configuration ver="2.0">
647	    <target name="CalculatorSubTest">
648	        <preparer>
649	            <option name="push" value="test.jpg -> /data/test/resource" src="res"/>
650	            <option name="push" value="libc++.z.so -> /data/test/resource" src="out"/>
651	        </preparer>
652	    </target>
653	</configuration>
654	```
6553. In the build file of the test cases, configure **resource\_config\_file** to point to the resource file **ohos\_test.xml**.
656	```
657	ohos_unittest("CalculatorSubTest") {
658	  resource_config_file = "//system/subsystem/partA/test/resource/calculator/ohos_test.xml"
659	}
660	```
661	>**Note:**
662	>- **target_name** indicates the test suite name defined in the **BUILD.gn** file in the **test** directory.**preparer** indicates the action to perform before the test suite is executed.
663	>- **src="res"** indicates that the test resources are in the **resource** directory under the **test** directory. **src="out"** indicates that the test resources are in the **out/release/$(*part*)** directory.
664
665## Executing Test Cases
666Before executing test cases, you need to modify the configuration based on the device used.
667
668### Modifying user_config.xml
669```
670<user_config>
671  <build>
672    <!-- Whether to build a demo case. The default value is false. If a demo case is required, change the value to true. -->
673    <example>false</example>
674    <!-- Whether to build the version. The default value is false. -->
675    <version>false</version>
676    <!-- Whether to build the test cases. The default value is true. If the build is already complete, change the value to false before executing the test cases.-->
677    <testcase>true</testcase>
678  </build>
679  <environment>
680    <!-- Configure the IP address and port number of the remote server to support connection to the device through the HarmonyOS Device Connector (HDC).-->
681    <device type="usb-hdc">
682      <ip></ip>
683      <port></port>
684      <sn></sn>
685    </device>
686    <!-- Configure the serial port information of the device to enable connection through the serial port.-->
687    <device type="com" label="ipcamera">
688      <serial>
689        <com></com>
690        <type>cmd</type>
691        <baud_rate>115200</baud_rate>
692        <data_bits>8</data_bits>
693        <stop_bits>1</stop_bits>
694        <timeout>1</timeout>
695      </serial>
696    </device>
697  </environment>
698  <!-- Configure the test case path. If the test cases have not been built (<testcase> is true), leave this parameter blank. If the build is complete, enter the path of the test cases.-->
699  <test_cases>
700    <dir></dir>
701  </test_cases>
702  <!-- Configure the coverage output path.-->
703  <coverage>
704    <outpath></outpath>
705  </coverage>
706  <!-- Configure the NFS mount information when the tested device supports only the serial port connection. Specify the NFS mapping path. host_dir indicates the NFS directory on the PC, and board_dir indicates the directory created on the board. -->
707  <NFS>
708    <host_dir></host_dir>
709    <mnt_cmd></mnt_cmd>
710    <board_dir></board_dir>
711  </NFS>
712</user_config>
713```
714>**Note**: If HDC is connected to the device before the test cases are executed, you only need to configure the device IP address and port number, and retain the default settings for other parameters.
715
716### Executing Test Cases on Windows
717#### Building Test Cases
718
719Test cases cannot be built on Windows. You need to run the following command to build test cases on Linux:
720```
721./build.sh --product-name Hi3516DV300 --build-target make_test
722```
723>Note:
724>- **product-name**: specifies the name of the product to build, for example, **Hi3516DV300**.
725>- **build-target**: specifies the test case to build. **make_test** indicates all test cases. You can specify the test cases based on requirements.
726
727After the build is complete, the test cases are automatically saved in **out/hi3516dv300/packages/phone/tests**.
728
729#### Setting Up the Execution Environment
7301. On Windows, create the **Test** directory in the test framework and then create the **testcase** directory in the **Test** directory.
731
7322. Copy **developertest** and **xdevice** from the Linux environment to the **Test** directory on Windows, and copy the test cases to the **testcase** directory.
733
734	>**Note**: Port the test framework and test cases from the Linux environment to the Windows environment for subsequent execution.
735
7363. Modify the **user_config.xml** file.
737	```
738	<build>
739	  <!-- Because the test cases have been built, change the value to false. -->
740	  <testcase>false</testcase>
741	</build>
742	<test_cases>
743	  <!-- The test cases are copied to the Windows environment. Change the test case output path to the path of the test cases in the Windows environment. -->
744	  <dir>D:\Test\testcase\tests</dir>
745	</test_cases>
746	```
747	>**Note**: `<testcase>` indicates whether to build test cases. `<dir>` indicates the path for searching for test cases.
748
749#### Executing Test Cases
7501. Start the test framework.
751	```
752	start.bat
753	```
7542. Select the product.
755
756    After the test framework starts, you are asked to select a product. Select the development board to test, for example, **Hi3516DV300**.
757
7583. Execute test cases.
759
760    Run the following command to execute test cases:
761	```
762	run -t UT -ts CalculatorSubTest -tc interger_sub_00l
763	```
764	In the command:
765	```
766	-t [TESTTYPE]: specifies the test case type, which can be UT, MST, ST, or PERF. This parameter is mandatory.
767	-tp [TESTPART]: specifies the part to test. This parameter can be used independently.
768	-tm [TESTMODULE]: specifies the module to test. This parameter must be specified together with -tp.
769	-ts [TESTSUITE]: specifies the test suite. This parameter can be used independently.
770	-tc [TESTCASE]: specifies the test case. This parameter must be specified together with -ts.
771	-You can run h to display help information.
772	```
773### Executing Test Cases on Linux
774#### Mapping the Remote Port
775To enable test cases to be executed on a remote Linux server or a Linux VM, map the port to enable communication between the device and the remote server or VM. Configure port mapping as follows:
7761. On the HDC server, run the following commands:
777	```
778	hdc_std kill
779	hdc_std -m -s 0.0.0.0:8710
780	```
781	>**Note**: The IP address and port number are default values.
782
7832. On the HDC client, run the following command:
784	```
785	hdc_std -s xx.xx.xx.xx:8710 list targets
786	```
787	>**Note**: Enter the IP address of the device to test.
788
789#### Executing Test Cases
7901. Start the test framework.
791	```
792	./start.sh
793	```
7942. Select the product.
795
796    After the test framework starts, you are asked to select a product. Select the development board to test, for example, **Hi3516DV300**.
797
7983. Execute test cases.
799
800    The test framework locates the test cases based on the command, and automatically builds and executes the test cases.
801	```
802	run -t UT -ts CalculatorSubTest -tc interger_sub_00l
803	```
804	In the command:
805	```
806	-t [TESTTYPE]: specifies the test case type, which can be UT, MST, ST, or PERF. This parameter is mandatory.
807	-tp [TESTPART]: specifies the part to test. This parameter can be used independently.
808	-tm [TESTMODULE]: specifies the module to test. This parameter must be specified together with -tp.
809	-ts [TESTSUITE]: specifies the test suite. This parameter can be used independently.
810	-tc [TESTCASE]: specifies the test case. This parameter must be specified together with -ts.
811	-You can run h to display help information.
812	```
813
814## Viewing the Test Report
815After the test cases are executed, the test result will be automatically generated. You can view the detailed test result in the related directory.
816
817### Test Result
818You can obtain the test result in the following directory:
819```
820test/developertest/reports/xxxx_xx_xx_xx_xx_xx
821```
822>**Note**: The folder for test reports is automatically generated.
823
824The folder contains the following files:
825| Type| Description|
826| ------------ | ------------ |
827| result/ |Test cases in standard format|
828| log/plan_log_xxxx_xx_xx_xx_xx_xx.log | Test case logs|
829| summary_report.html | Test report summary|
830| details_report.html | Detailed test report|
831
832### Test Framework Logs
833```
834reports/platform_log_xxxx_xx_xx_xx_xx_xx.log
835```
836
837### Latest Test Report
838```
839reports/latest
840```
841