未验证 提交 e4a4b118 编写于 作者: O openharmony_ci 提交者: Gitee

!11344 优化测试文档

Merge pull request !11344 from ry/master
# 设备测试
- [developer_test开发者自测试执行框架使用指导](developer_test.md)
- [xdevice测试调度框架使用指导](xdevice.md)
- [XTS用例开发指导](xts.md)
...@@ -20,10 +20,104 @@ OpenHarmony系统开发人员在新增或修改代码之后,希望可以快速 ...@@ -20,10 +20,104 @@ OpenHarmony系统开发人员在新增或修改代码之后,希望可以快速
## 环境准备 ## 环境准备
开发自测试框架依赖于python运行环境,python版本为3.8.X,在使用测试框架之前可参阅以下方式进行配置。 开发自测试框架依赖于python运行环境,python版本为3.7.5及以上版本,在使用测试框架之前可参阅以下方式进行配置。
- [环境配置](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-testguide-test.md#%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE) 源码获取可[参考](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/sourcecode-acquire.md)
- [源码获取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/sourcecode-acquire.md)
### 自测试框架基础环境依赖
| 环境依赖 | 版本型号 | 详细说明 |
| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| 操作系统 | Ubuntu18.04及以上 | 代码编译环境 |
| Linux系统扩展组件 | libreadline-dev | 命令行读取插件 |
| python | 3.7.5版本及以上 | 测试框架语言 |
| python插件 | pyserial 3.3及以上、paramiko2.7.1及以上、setuptools40.8.0及以上、rsa4.0及以上 | pserial:支持python的串口通信;paramiko:支持python使用SSH协议;setuptools:支持python方便创建和分发python包;rsa:支持python rsa加密 |
| NFS Server | haneWIN NFS Server 1.2.50及以上或者 NFS v4及以上 | 支持设备通过串口连接,使用轻量、小型设备 |
| HDC | 1.1.0 | 支持设备通过HDC连接 |
1. 安装Linux扩展组件readline,安装命令如下:
```bash
sudo apt-get install libreadline-dev
```
安装成功提示如下:
```
Reading package lists... Done
Building dependency tree
Reading state information... Done
libreadline-dev is already the newest version (7.0-3).
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.
```
2. 安装setuptools插件,安装命令如下:
```bash
pip3 install setuptools
```
安装成功提示如下:
```
Requirement already satisfied: setuptools in d:\programs\python37\lib\site-packages (41.2.0)
```
3. 安装paramiko插件,安装命令如下:
```bash
pip3 install paramiko
```
安装成功提示如下:
```
Installing collected packages: pycparser, cffi, pynacl, bcrypt, cryptography, paramiko
Successfully installed bcrypt-3.2.0 cffi-1.14.4 cryptography-3.3.1 paramiko-2.7.2 pycparser-2.20 pynacl-1.4.0
```
4. 安装python的rsa插件,安装命令如下:
```bash
pip3 install rsa
```
安装成功提示如下:
```
Installing collected packages: pyasn1, rsa
Successfully installed pyasn1-0.4.8 rsa-4.7
```
5. 安装串口插件pyserial,安装命令如下:
```bash
pip3 install pyserial
```
安装成功提示如下:
```
Requirement already satisfied: pyserial in d:\programs\python37\lib\site-packages\pyserial-3.4-py3.7.egg (3.4)
```
6. 如果设备仅支持串口输出测试结果,则需要安装NFS Server
> 针对小型或轻量设备
- Windows环境下安装,安装haneWIN NFS Server1.2.50软件包。
- Linux环境下安装,安装命令如下:
```bash
sudo apt install nfs-kernel-server
```
安装成功提示如下:
```
Reading package lists... Done
Building dependency tree
Reading state information... Done
nfs-kernel-server is already the newest version (1:1.3.4-2.1ubuntu5.3).
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.
```
7. 如果设备支持HDC连接,则需要安装HDC工具,安装流程请参考[HDC-OpenHarmony设备连接器](https://gitee.com/openharmony/developtools_hdc_standard/blob/master/README_zh.md)
### 环境依赖检查
| 检查项 | 操作 | 满足环境 |
| -------------------------------------------------- | --------------------------------------------------- | ------------------------- |
| 检查python安装成功 | 命令行窗口执行命令:python --version | 版本不小于3.7.5即可 |
| 检查python扩展插件安装成功 | 打开test/developertest目录,执行start.bat或start.sh | 可进入提示符“>>>”界面即可 |
| 检查NFS Server启动状态(被测设备仅支持串口时检测) | 通过串口登录开发板,执行mount命令挂载NFS | 可正常挂载文件目录即可 |
| 检查HDC安装成功 | 命令行窗口执行命令:hdc_std -v | 版本不小于1.1.0即可 |
## 编写测试用例 ## 编写测试用例
...@@ -41,7 +135,7 @@ calculator_sub_test.cpp ...@@ -41,7 +135,7 @@ calculator_sub_test.cpp
``` ```
用例示例 用例示例
``` ```c++
/* /*
* Copyright (c) 2021 XXXX Device Co., Ltd. * Copyright (c) 2021 XXXX Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -128,7 +222,7 @@ HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1) ...@@ -128,7 +222,7 @@ HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1)
2.引用测试框架头文件和命名空间 2.引用测试框架头文件和命名空间
``` ```c++
#include <gtest/gtest.h> #include <gtest/gtest.h>
using namespace testing::ext; using namespace testing::ext;
...@@ -136,13 +230,13 @@ using namespace testing::ext; ...@@ -136,13 +230,13 @@ using namespace testing::ext;
3.添加被测试类的头文件 3.添加被测试类的头文件
``` ```c++
#include "calculator.h" #include "calculator.h"
``` ```
4.定义测试套(测试类) 4.定义测试套(测试类)
``` ```c++
class CalculatorSubTest : public testing::Test { class CalculatorSubTest : public testing::Test {
public: public:
static void SetUpTestCase(void); static void SetUpTestCase(void);
...@@ -169,13 +263,13 @@ void CalculatorSubTest::SetUp(void) ...@@ -169,13 +263,13 @@ void CalculatorSubTest::SetUp(void)
void CalculatorSubTest::TearDown(void) void CalculatorSubTest::TearDown(void)
{ {
// input testcase teardown step,teardown invoked after each testcases // input testcase teardown step,teardown invoked after each testcases
} }==
``` ```
> **注意:** 在定义测试套时,测试套名称应与编译目标保持一致,采用大驼峰风格。 > **注意:** 在定义测试套时,测试套名称应与编译目标保持一致,采用大驼峰风格。
5.测试用例实现,包含用例注释和逻辑实现 5.测试用例实现,包含用例注释和逻辑实现
``` ```c++
/** /**
* @tc.name: integer_sub_001 * @tc.name: integer_sub_001
* @tc.desc: Verify the sub function. * @tc.desc: Verify the sub function.
...@@ -242,7 +336,7 @@ AppInfoTest.js ...@@ -242,7 +336,7 @@ AppInfoTest.js
- 用例示例 - 用例示例
``` ```js
/* /*
* Copyright (C) 2021 XXXX Device Co., Ltd. * Copyright (C) 2021 XXXX Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -316,13 +410,13 @@ describe("AppInfoTest", function () { ...@@ -316,13 +410,13 @@ describe("AppInfoTest", function () {
*/ */
``` ```
2. 导入被测api和jsunit测试库 2. 导入被测api和jsunit测试库
``` ```js
import app from '@system.app' import app from '@system.app'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
``` ```
3. 定义测试套(测试类) 3. 定义测试套(测试类)
``` ```js
describe("AppInfoTest", function () { describe("AppInfoTest", function () {
beforeAll(function() { beforeAll(function() {
// input testsuit setup step,setup invoked before all testcases // input testsuit setup step,setup invoked before all testcases
...@@ -345,7 +439,7 @@ describe("AppInfoTest", function () { ...@@ -345,7 +439,7 @@ describe("AppInfoTest", function () {
}) })
``` ```
4. 测试用例实现 4. 测试用例实现
``` ```JS
/* /*
* @tc.name:appInfoTest001 * @tc.name:appInfoTest001
* @tc.desc:verify app info is not null * @tc.desc:verify app info is not null
...@@ -360,7 +454,7 @@ describe("AppInfoTest", function () { ...@@ -360,7 +454,7 @@ describe("AppInfoTest", function () {
expect(info != null).assertEqual(true) expect(info != null).assertEqual(true)
}) })
``` ```
> **注意:** @tc.require: 格式必须以AR/SR或issue开头: 如:issueI56WJ7 > **注意:** @tc.require: 格式必须以issue开头: 如:issueI56WJ7
**Fuzz测试** **Fuzz测试**
...@@ -546,7 +640,7 @@ ohos_js_unittest("GetAppInfoJsTest") { ...@@ -546,7 +640,7 @@ ohos_js_unittest("GetAppInfoJsTest") {
``` ```
config.json为hap编译所需配置文件,需要开发者根据被测sdk版本配置“target”项,其余项可默认,具体如下所示: config.json为hap编译所需配置文件,需要开发者根据被测sdk版本配置“target”项,其余项可默认,具体如下所示:
``` ```json
{ {
"app": { "app": {
"bundleName": "com.example.myapplication", "bundleName": "com.example.myapplication",
...@@ -659,7 +753,7 @@ group("unittest") { ...@@ -659,7 +753,7 @@ group("unittest") {
2.在resource目录下对应的模块目录中创建一个ohos_test.xml文件,文件内容格式如下: 2.在resource目录下对应的模块目录中创建一个ohos_test.xml文件,文件内容格式如下:
``` ```xml
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration ver="2.0"> <configuration ver="2.0">
<target name="CalculatorSubTest"> <target name="CalculatorSubTest">
...@@ -689,7 +783,7 @@ ohos_unittest("CalculatorSubTest") { ...@@ -689,7 +783,7 @@ ohos_unittest("CalculatorSubTest") {
在执行测试用例之前,针对用例使用设备的不同,需要对相应配置进行修改,修改完成即可执行测试用例。 在执行测试用例之前,针对用例使用设备的不同,需要对相应配置进行修改,修改完成即可执行测试用例。
#### user_config.xml配置 #### user_config.xml配置
``` ```xml
<user_config> <user_config>
<build> <build>
<!-- 是否编译demo用例, 默认为false,如果需要编译demo可修改为true --> <!-- 是否编译demo用例, 默认为false,如果需要编译demo可修改为true -->
...@@ -788,7 +882,7 @@ ohos_unittest("CalculatorSubTest") { ...@@ -788,7 +882,7 @@ ohos_unittest("CalculatorSubTest") {
>**说明:** 将测试框架及测试用例从Linux环境移植到Windows环境,以便后续执行。 >**说明:** 将测试框架及测试用例从Linux环境移植到Windows环境,以便后续执行。
3. 修改user_config.xml 3. 修改user_config.xml
``` ```xml
<build> <build>
<!-- 由于测试用例已编译完成,此标签属性需改为false --> <!-- 由于测试用例已编译完成,此标签属性需改为false -->
<testcase>false</testcase> <testcase>false</testcase>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册