未验证 提交 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系统开发人员在新增或修改代码之后,希望可以快速
## 环境准备
开发自测试框架依赖于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
```
用例示例
```
```c++
/*
* Copyright (c) 2021 XXXX Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
......@@ -128,7 +222,7 @@ HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1)
2.引用测试框架头文件和命名空间
```
```c++
#include <gtest/gtest.h>
using namespace testing::ext;
......@@ -136,13 +230,13 @@ using namespace testing::ext;
3.添加被测试类的头文件
```
```c++
#include "calculator.h"
```
4.定义测试套(测试类)
```
```c++
class CalculatorSubTest : public testing::Test {
public:
static void SetUpTestCase(void);
......@@ -169,13 +263,13 @@ void CalculatorSubTest::SetUp(void)
void CalculatorSubTest::TearDown(void)
{
// input testcase teardown step,teardown invoked after each testcases
}
}==
```
> **注意:** 在定义测试套时,测试套名称应与编译目标保持一致,采用大驼峰风格。
5.测试用例实现,包含用例注释和逻辑实现
```
```c++
/**
* @tc.name: integer_sub_001
* @tc.desc: Verify the sub function.
......@@ -242,7 +336,7 @@ AppInfoTest.js
- 用例示例
```
```js
/*
* Copyright (C) 2021 XXXX Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
......@@ -316,13 +410,13 @@ describe("AppInfoTest", function () {
*/
```
2. 导入被测api和jsunit测试库
```
```js
import app from '@system.app'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
```
3. 定义测试套(测试类)
```
```js
describe("AppInfoTest", function () {
beforeAll(function() {
// input testsuit setup step,setup invoked before all testcases
......@@ -345,7 +439,7 @@ describe("AppInfoTest", function () {
})
```
4. 测试用例实现
```
```JS
/*
* @tc.name:appInfoTest001
* @tc.desc:verify app info is not null
......@@ -360,7 +454,7 @@ describe("AppInfoTest", function () {
expect(info != null).assertEqual(true)
})
```
> **注意:** @tc.require: 格式必须以AR/SR或issue开头: 如:issueI56WJ7
> **注意:** @tc.require: 格式必须以issue开头: 如:issueI56WJ7
**Fuzz测试**
......@@ -546,7 +640,7 @@ ohos_js_unittest("GetAppInfoJsTest") {
```
config.json为hap编译所需配置文件,需要开发者根据被测sdk版本配置“target”项,其余项可默认,具体如下所示:
```
```json
{
"app": {
"bundleName": "com.example.myapplication",
......@@ -659,7 +753,7 @@ group("unittest") {
2.在resource目录下对应的模块目录中创建一个ohos_test.xml文件,文件内容格式如下:
```
```xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration ver="2.0">
<target name="CalculatorSubTest">
......@@ -689,7 +783,7 @@ ohos_unittest("CalculatorSubTest") {
在执行测试用例之前,针对用例使用设备的不同,需要对相应配置进行修改,修改完成即可执行测试用例。
#### user_config.xml配置
```
```xml
<user_config>
<build>
<!-- 是否编译demo用例, 默认为false,如果需要编译demo可修改为true -->
......@@ -788,7 +882,7 @@ ohos_unittest("CalculatorSubTest") {
>**说明:** 将测试框架及测试用例从Linux环境移植到Windows环境,以便后续执行。
3. 修改user_config.xml
```
```xml
<build>
<!-- 由于测试用例已编译完成,此标签属性需改为false -->
<testcase>false</testcase>
......
......@@ -28,7 +28,7 @@ XTS子系统当前包括acts与tools软件包:
## 目录
```
/test/xts
├── acts # 测试代码存放目录
......@@ -102,7 +102,7 @@ XTS子系统当前包括acts与tools软件包:
当前使用的测试框架是hctest,hctest测试框架支持使用C语言编写测试用例,是在开源测试框架unity的基础上进行增强和适配。
1. 用例目录规范:测试用例存储到test/xts/acts仓中。
```
├── acts
│ └──subsystem_lite
......@@ -116,14 +116,14 @@ XTS子系统当前包括acts与tools软件包:
2. src目录下用例编写样例。
1.引用测试框架
```
#include "hctest.h"
```
2. 使用宏定义LITE_TEST_SUIT定义子系统、模块、测试套件名称
```
/**
* @brief register a test suite named "IntTestSuite"
......@@ -159,7 +159,7 @@ XTS子系统当前包括acts与tools软件包:
3. 测试模块的配置文件(BUILD.gn)样例:
在每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后静态库的名称、依赖的头文件、依赖的库等;具体写法如下:
```
import("//test/xts/tools/lite/build/suite_lite.gni")
hctest_suite("ActsDemoTest") {
......@@ -175,7 +175,7 @@ XTS子系统当前包括acts与tools软件包:
4. acts下BUILD.gn增加编译选项。
需要将测试模块加入到acts目录下的编译脚本中,编译脚本路径:test/xts/acts/build_lite/BUILD.gn。
```
lite_component("acts") {
...
......@@ -220,7 +220,7 @@ XTS子系统当前包括acts与tools软件包:
当前使用的测试框架是hcpptest,hcpptest测试框架是在开源的googletest测试框架的基础上进行的增强和适配。
1. 规范用例目录:测试用例存储到test/xts/acts仓中。
```
├── acts
│ └──subsystem_lite
......@@ -236,14 +236,14 @@ XTS子系统当前包括acts与tools软件包:
需要引用gtest.h 如:\#include "gtest/gtest.h"
```
#include "gtest/gtest.h"
```
2. 定义Setup与TearDown
```
using namespace std;
using namespace testing::ext;
......@@ -271,10 +271,10 @@ XTS子系统当前包括acts与tools软件包:
普通测试用例的定义:HWTEST(测试套名称, 测试用例名称, 用例标注)。
包含SetUp和TearDown的测试用例的定义 :HWTEST_F(测试套名称, 测试用例名称,用例标注)。
宏定义包括三个参数:测试套件名称,测试用例名称,用例属性(测试类型、用例粒度、用例级别)。
```
HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) {
// do something
......@@ -285,7 +285,7 @@ XTS子系统当前包括acts与tools软件包:
每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后可执行文件的名称、依赖的头文件、依赖的库等;具体写法如下。每个测试模块将独立编译成.bin可执行文件, 该文件可直接push到单板上进行测试。
举例:
```
import("//test/xts/tools/lite/build/suite_lite.gni")
hcpptest_suite("ActsDemoTest") {
......@@ -309,7 +309,7 @@ XTS子系统当前包括acts与tools软件包:
4. acts目录下增加编译选项(BUILD.gn)样例:
将测试模块加入到acts目录下的编译脚本中,编译脚本为:test/xts/acts/build_lite/BUILD.gn。
```
lite_component("acts") {
...
......@@ -346,7 +346,7 @@ XTS子系统当前包括acts与tools软件包:
格式:mount [nfs服务器IP]:[/nfs共享目录] [/开发板目录] nfs
举例:
```
mount 192.168.1.10:/nfs /nfs nfs
```
......@@ -377,7 +377,7 @@ XTS子系统当前包括acts与tools软件包:
用例编写语法采用 jasmine 的标准语法,格式支持ES6格式。
1. 规范用例目录:测试用例存储到entry/src/main/js/test目录。
```
├── BUILD.gn
│ └──entry
......@@ -394,7 +394,7 @@ XTS子系统当前包括acts与tools软件包:
```
2. index.js示例
```
// 拉起js测试框架,加载测试用例
import {Core, ExpectExtend} from 'deccjsunit/index'
......@@ -425,7 +425,7 @@ XTS子系统当前包括acts与tools软件包:
```
3. 单元测试用例示例
```
// Example1: 使用HJSUnit进行单元测试
describe('appInfoTest', function () {
......@@ -447,7 +447,7 @@ hap包编译请参考[标准系统js应用开发指导](https://developer.harmon
1. 全量编译
**命令**
```
./build.sh suite=acts system_size=standard
```
......@@ -464,7 +464,7 @@ hap包编译请参考[标准系统js应用开发指导](https://developer.harmon
Windows工作台下安装python3.7及以上版本,确保工作台和测试设备正常连接。
**测试执行目录**(对应编译生成的out/release/suites/acts目录)
```
├── testcase # 测试套文件存放目录
│ └──xxx.hap # 测试套可执行hap文件
......@@ -480,7 +480,7 @@ Windows工作台下安装python3.7及以上版本,确保工作台和测试设
2. 界面启动后,输入用例执行指令。
- 全量执行
```
run acts
```
......@@ -490,7 +490,7 @@ Windows工作台下安装python3.7及以上版本,确保工作台和测试设
![zh-cn_image_0000001200230833](figures/zh-cn_image_0000001200230833.gif)
- 模块执行(具体模块可以查看\acts\testcases\)
```
run –l ActsSamgrTest
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册