Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
0d30bf64
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0d30bf64
编写于
6月 27, 2023
作者:
O
openharmony_ci
提交者:
Gitee
6月 27, 2023
浏览文件
操作
浏览文件
下载
差异文件
!20087 【资料刷新】开发自测试执行框架对外资料刷新
Merge pull request !20087 from very0228/master
上级
2f4c00c3
20c28f02
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
938 addition
and
630 deletion
+938
-630
zh-cn/device-dev/device-test/developer_test.md
zh-cn/device-dev/device-test/developer_test.md
+938
-630
未找到文件。
zh-cn/device-dev/device-test/developer_test.md
浏览文件 @
0d30bf64
...
@@ -15,29 +15,33 @@ OpenHarmony系统开发人员在新增或修改代码之后,希望可以快速
...
@@ -15,29 +15,33 @@ OpenHarmony系统开发人员在新增或修改代码之后,希望可以快速
### 约束与限制
### 约束与限制
-
框架使用时必须提前连接OpenHarmony设备方可执行测试用例。
框架使用时必须提前连接OpenHarmony设备方可执行测试用例。
## 环境准备
## 环境准备
开发自测试框架依赖于python运行环境
,python版本为3.7.5及以上版本,
在使用测试框架之前可参见以下方式进行配置。
开发自测试框架依赖于python运行环境
,python版本为3.7.5及以上版本,
在使用测试框架之前可参见以下方式进行配置。
源码获取可
[
参考
](
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
)
。
### 自测试框架基础环境依赖
### 自测试框架基础环境依赖
| 环境依赖 | 版本型号 | 详细说明 |
| 环境依赖 | 版本型号 | 详细说明 |
| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| 操作系统 | Ubuntu
18
.04及以上 | 代码编译环境 |
| 操作系统 | Ubuntu
20
.04及以上 | 代码编译环境 |
| Linux系统扩展组件 | libreadline-dev | 命令行读取插件 |
| Linux系统扩展组件 | libreadline-dev | 命令行读取插件 |
| python | 3.7.5版本及以上 | 测试框架语言 |
| 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加密 |
| 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及以上 | 支持设备通过串口连接,使用轻量、小型设备 |
| NFS Server | haneWIN NFS Server 1.2.50及以上或者 NFS v4及以上 | 支持设备通过串口连接,使用轻量、小型设备 |
| HDC | 1.
1.0
| 支持设备通过HDC连接 |
| HDC | 1.
2.0a
| 支持设备通过HDC连接 |
1.
安装Linux扩展组件readline,安装命令如下:
1.
安装Ubuntu的步骤如下:
参考此文[OpenHarmony-标准设备系统代码操作梳理](https://blog.csdn.net/nanzhanfei/article/details/121951919),按照第二章“WSL2安装”步骤操作,即可完成Ubuntu的安装。由于Ubuntu20已自带python3.8.5,无需再次安装python。
2.
安装Linux扩展组件readline,安装命令如下:
```bash
```bash
sudo apt-get install libreadline-dev
sudo apt-get install libreadline-dev
...
@@ -91,7 +95,9 @@ OpenHarmony系统开发人员在新增或修改代码之后,希望可以快速
...
@@ -91,7 +95,9 @@ OpenHarmony系统开发人员在新增或修改代码之后,希望可以快速
6.
如果设备仅支持串口输出测试结果,则需要安装NFS Server
6.
如果设备仅支持串口输出测试结果,则需要安装NFS Server
> 针对小型或轻量设备
>  **说明:**
>
> 此操作针对小型或轻量设备,不针对标准设备。
- Windows环境下安装,安装haneWIN NFS Server1.2.50软件包。
- Windows环境下安装,安装haneWIN NFS Server1.2.50软件包。
- Linux环境下安装,安装命令如下:
- Linux环境下安装,安装命令如下:
...
@@ -117,27 +123,24 @@ OpenHarmony系统开发人员在新增或修改代码之后,希望可以快速
...
@@ -117,27 +123,24 @@ OpenHarmony系统开发人员在新增或修改代码之后,希望可以快速
| 检查python安装成功 | 命令行窗口执行命令:python --version | 版本不小于3.7.5即可 |
| 检查python安装成功 | 命令行窗口执行命令:python --version | 版本不小于3.7.5即可 |
| 检查python扩展插件安装成功 | 打开test/developertest目录,执行start.bat或start.sh | 可进入提示符“>>>”界面即可 |
| 检查python扩展插件安装成功 | 打开test/developertest目录,执行start.bat或start.sh | 可进入提示符“>>>”界面即可 |
| 检查NFS Server启动状态(被测设备仅支持串口时检测) | 通过串口登录开发板,执行mount命令挂载NFS | 可正常挂载文件目录即可 |
| 检查NFS Server启动状态(被测设备仅支持串口时检测) | 通过串口登录开发板,执行mount命令挂载NFS | 可正常挂载文件目录即可 |
| 检查HDC安装成功 | 命令行窗口执行命令:hdc
_std -v | 版本不小于1.1.0
即可 |
| 检查HDC安装成功 | 命令行窗口执行命令:hdc
-v | 版本不小于1.2.0a
即可 |
## 编写测试用例
## 编写测试用例
本测试框架支持多种类型测试,针对不同测试类型提供了不同的用例编写模板以供参考。
_
本测试框架支持多种类型测试,针对不同测试类型提供了不同的用例编写模板以供参考。
**TDD测试(C++)**
**TDD测试(C++)**
用例源文件命名规范
-
用例源文件命名规范
测试用例源文件名称和测试套内容保持一致,文件命名采用全小写+下划线方式命名,以test结尾,具体格式为:[功能]_[子功能]_test,子功能支持向下细分。
测试用例源文件名称和测试套内容保持一致,文件命名采用全小写+下划线格式,以test结尾,具体格式为:[功能]_[子功能]_test,子功能支持向下细分。
示例:
```
calculator_sub_test.cpp
```
用例示例
```
c++
-
单线程用例示例及编写步骤,以calculator_sub_test.cpp为例进行说明:
/*
```
* Copyright (c) 2021 XXXX Device Co., Ltd.
/*
* Copyright (c) 2023 XXXX Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* You may obtain a copy of the License at
...
@@ -151,61 +154,59 @@ calculator_sub_test.cpp
...
@@ -151,61 +154,59 @@ calculator_sub_test.cpp
* limitations under the License.
* limitations under the License.
*/
*/
#include "calculator.h"
#include "calculator.h"
#include <gtest/gtest.h>
#include <gtest/gtest.h>
using
namespace
testing
::
ext
;
using namespace testing::ext;
class
CalculatorSubTest
:
public
testing
::
Test
{
class CalculatorSubTest : public testing::Test {
public:
public:
static void SetUpTestCase(void);
static void SetUpTestCase(void);
static void TearDownTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void SetUp();
void TearDown();
void TearDown();
};
};
void
CalculatorSubTest
::
SetUpTestCase
(
void
)
void CalculatorSubTest::SetUpTestCase(void)
{
{
// input testsuit setup step,setup invoked before all testcases
// input testsuit setup step,setup invoked before all testcases
}
}
void
CalculatorSubTest
::
TearDownTestCase
(
void
)
void CalculatorSubTest::TearDownTestCase(void)
{
{
// input testsuit teardown step,teardown invoked after all testcases
// input testsuit teardown step,teardown invoked after all testcases
}
}
void
CalculatorSubTest
::
SetUp
(
void
)
void CalculatorSubTest::SetUp(void)
{
{
// input testcase setup step,setup invoked before each testcases
// input testcase setup step,setup invoked before each testcases
}
}
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
}
}
/**
/**
* @tc.name: integer_sub_001
* @tc.name: integer_sub_001
* @tc.desc: Verify the sub function.
* @tc.desc: Verify the sub function.
* @tc.type: FUNC
* @tc.type: FUNC
* @tc.require: issueNumber
* @tc.require: issueNumber
*/
*/
HWTEST_F
(
CalculatorSubTest
,
integer_sub_001
,
TestSize
.
Level1
)
HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1)
{
{
// step 1:调用函数获取结果
// step 1:调用函数获取结果
int actual = Sub(4,0);
int actual = Sub(4,0);
// Step 2:使用断言比较预期与实际结果
// Step 2:使用断言比较预期与实际结果
EXPECT_EQ(4, actual);
EXPECT_EQ(4, actual);
}
}
```
```
详细内容介绍:
详细内容介绍:
1.
添加测试用例文件头注释信息
1.
添加测试用例文件头注释信息
```
/*
```
* Copyright (c) 2023 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");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* You may obtain a copy of the License at
...
@@ -218,127 +219,260 @@ HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1)
...
@@ -218,127 +219,260 @@ HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1)
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
```
```
2. 引用测试框架头文件和命名空间
2.
引用测试框架头文件和命名空间
```
#include
<gtest
/
gtest.h
>
```
c++
#include <gtest/gtest.h>
using
namespace
testing
::
ext
;
```
3.
添加被测试类的头文件
```
c++
#include "calculator.h"
```
4.
定义测试套(测试类)
```
c++
using namespace testing::ext;
class
CalculatorSubTest
:
public
testing
::
Test
{
```
public:
3. 添加被测试类的头文件
```
#include "calculator.h"
```
4.
定义测试套(测试类)
> **注意:** 在定义测试套时,测试套名称应与编译目标保持一致,采用大驼峰风格。
```
class CalculatorSubTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void SetUpTestCase(void);
static void TearDownTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void SetUp();
void TearDown();
void TearDown();
};
};
void
CalculatorSubTest
::
SetUpTestCase
(
void
)
void CalculatorSubTest::SetUpTestCase(void)
{
{
// input testsuit setup step,setup invoked before all testcases
// input testsuit setup step,setup invoked before all testcases
}
}
void
CalculatorSubTest
::
TearDownTestCase
(
void
)
void CalculatorSubTest::TearDownTestCase(void)
{
{
// input testsuit teardown step,teardown invoked after all testcases
// input testsuit teardown step,teardown invoked after all testcases
}
}
void
CalculatorSubTest
::
SetUp
(
void
)
void CalculatorSubTest::SetUp(void)
{
{
// input testcase setup step,setup invoked before each testcases
// input testcase setup step,setup invoked before each testcases
}
}
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.
测试用例实现,包含用例注释和逻辑实现
```
c++
5. 测试用例实现,包含用例注释和逻辑实现
/**
```
/
**
*
@tc.name: integer_sub_001
*
@tc.name: integer_sub_001
*
@tc.desc: Verify the sub function.
*
@tc.desc: Verify the sub function.
*
@tc.type: FUNC
*
@tc.type: FUNC
*
@tc.require: issueNumber
*
@tc.require: issueNumber
*
/
*
/
HWTEST_F
(
CalculatorSubTest
,
integer_sub_001
,
TestSize
.
Level1
)
HWTEST_F(CalculatorSubTest, integer_sub_001, TestSize.Level1)
{
{
//step 1:调用函数获取结果
//step 1:调用函数获取结果
int actual = Sub(4,0);
int actual = Sub(4,0);
//Step 2:使用断言比较预期与实际结果
//Step 2:使用断言比较预期与实际结果
EXPECT_EQ(4, actual);
EXPECT_EQ(4, actual);
}
}
```
```
> **注意:** @tc.require: 格式必须以AR/SR或issue开头: 如:issueI56WJ7
> **注意:** @tc.require的取值必须以AR/SR或issue开头,如:issueI56WJ7。
在编写用例时,我们提供了三种用例模板供您选择。
- 多线程用例示例及编写步骤,以base_object_test.cpp为例进行说明:
```
// 测试用例文件头注释信息及用例注释同单线程用例示例。
| 类型 | 描述 |
#include "base_object.h"
| --------------- | ------------------------------------------------ |
#include <gtest/gtest.h>
| HWTEST(A,B,C) | 用例执行不依赖Setup&Teardown时,可选取 |
#include <gtest/hwext/gtest-multithread.h>
| HWTEST_F(A,B,C) | 用例执行(不含参数)依赖于Setup&Teardown时,可选取 |
#include <unistd.h>
| HWTEST_P(A,B,C) | 用例执行(含参数)依赖于Set&Teardown时,可选取 |
其中,参数A,B,C的含义如下:
using namespace testing::ext;
using namespace testing::mt;
-
参数A为测试套名。
namespace OHOS {
namespace AAFwk {
class AAFwkBaseObjectTest : public testing::Test {......}
-
参数B为测试用例名,其命名必须遵循[功能点]_[编号]的格式,编号为3位数字,从001开始。
// Step 1:待测函数,返回阶乘结果
int factorial(int n)
{
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
printf("Factorial Function Result : %d! = %d\n", n, result);
return result;
}
-
参数C为测试用例等级,具体分为门禁level0 以及非门禁level1-level4共五个等级,其中非门禁level1-level4等级的具体选取规则为:测试用例功能越重要,level等级越低。
// Step 2:使用断言比较预期与实际结果
void factorial_test()
{
int ret = factorial(3); // 调用函数获取结果
std::thread::id this_id = std::this_thread::get_id();
std::ostringstream oss;
oss << this_id;
std::string this_id_str = oss.str();
long int thread_id = atol(this_id_str.c_str());
printf("running thread...: %ld\n", thread_id); // 输出当前线程的id
EXPECT_EQ(ret, 6);
}
HWTEST_F(AAFwkBaseObjectTest, Factorial_test_001, TestSize.Level1)
{
SET_THREAD_NUM(4);
printf("Factorial_test_001 BEGIN\n");
GTEST_RUN_TASK(factorial_test);
printf("Factorial_test_001 END\n");
}
**注意:**
HWMTEST_F(AAFwkBaseObjectTest, Factorial_test_002, TestSize.Level1, 6)
{
printf("Factorial_test_002 BEGIN\n");
factorial_test();
printf("Factorial_test_002 END\n");
}
-
测试用例的预期结果必须有对应的断言。
} // namespace AAFwk
} // namespace OHOS
-
测试用例必须填写用例等级。
```
详细内容介绍:
1. 添加测试用例文件头注释信息
-
测试体建议按照模板分步实现
。
> **注意:** 与单线程用例标准一致
。
-
用例描述信息按照标准格式@tc.xxx value书写,注释信息必须包含用例名称,用例描述,用例类型,需求编号四项。其中用例测试类型@tc.type参数的选取,可参考下表。
2. 引用测试框架头文件和命名空间
```
#include <gtest/gtest.h>
#include <gtest/hwext/gtest-multithread.h>
#include <unistd.h>
using namespace testing::ext;
using namespace testing::mt;
```
3.
添加被测试类的头文件
```
#include "base_object.h"
```
4. 定义测试套(测试类)
```
class AAFwkBaseObjectTest : public testing::Test {......}
```
> **注意:** 与单线程用例标准一致。
5. 测试用例实现,包含用例注释和逻辑实现
```
// Step 1:待测函数,返回阶乘结果
int factorial(int n)
{
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
printf("Factorial Function Result : %d! = %d\n", n, result);
return result;
}
// Step 2:使用断言比较预期与实际结果
void factorial_test()
{
int ret = factorial(3); // 调用函数获取结果
std::thread::id this_id = std::this_thread::get_id();
std::ostringstream oss;
oss << this_id;
std::string this_id_str = oss.str();
long int thread_id = atol(this_id_str.c_str());
printf("running thread...: %ld\n", thread_id); // 输出当前线程的id
EXPECT_EQ(ret, 6);
}
// GTEST_RUN_TASK(TestFunction)多线程启动函数,参数为自定义函数。
// 未调用SET_THREAD_NUM()时,默认线程数10个。
HWTEST_F(AAFwkBaseObjectTest, Factorial_test_001, TestSize.Level1)
{
SET_THREAD_NUM(4); // 设置线程数量,同一测试套中可动态设置线程数。
printf("Factorial_test_001 BEGIN\n");
GTEST_RUN_TASK(factorial_test); // 启动factorial_test任务的多线程执行
printf("Factorial_test_001 END\n");
}
// HWMTEST_F(TEST_SUITE, TEST_TC, TEST_LEVEL, THREAD_NUM)
// THREAD_NUM可设置用例执行的线程数量。
// HWMTEST_F会创建指定数量的线程并执行被测函数。
HWMTEST_F(AAFwkBaseObjectTest, Factorial_test_002, TestSize.Level1, 6)
{
printf("Factorial_test_002 BEGIN\n");
factorial_test();
printf("Factorial_test_002 END\n");
}
// 新增多线程接口MTEST_ADD_TASK(THREAD_ID,ThreadTestFunc),注册多线程,但不在该用例中执行,之后统一执行,适合多个用例组合场景下的多线程测试。
// THREAD_ID从0开始定义区别不同的线程,也可以使用随机THREAD_ID,即传入RANDOM_THREAD_ID,此场景下THREAD_ID是不会重复的。
// 新增多线程接口MTEST_POST_RUN(),统一执行之前注册的多线程用例。
```
> **注意:** 多线程用例注释与单线程用例标准一致。
-
C++用例模板说明:
在编写用例时,我们提供了四种用例模板供您选择。
| 类型 | 描述 |
| ------------| ------------|
| HWTEST(A,B,C)| 用例执行不依赖Setup&Teardown时,可选取|
| HWTEST_F(A,B,C)| 用例执行(不含参数)依赖于Setup&Teardown时,可选取|
| HWMTEST_F(A,B,C,D)| 多线程用例执行依赖于Setup&Teardown时,可选取|
| HWTEST_P(A,B,C)| 用例执行(含参数)依赖于Set&Teardown时,可选取|
其中,参数A,B,C的含义如下:
- 参数A为测试套名。
- 参数B为测试用例名,其命名必须遵循[功能点]_[编号]的格式,编号为3位数字,从001开始。
| 测试类型名称 | 类型编码 |
- 参数C为测试用例等级,具体分为门禁level0 以及非门禁level1-level4共五个等级,其中非门禁level1-level4等级的具体选取规则为:测试用例功能越重要,level等级越低。
| ------------ | -------- |
| 功能测试 | FUNC |
| 性能测试 | PERF |
| 可靠性测试 | RELI |
| 安全测试 | SECU |
| 模糊测试 | FUZZ |
**TDD测试(JS)**
- 参数D为多线程用例执行的线程数量设置。
**注意:**
- 测试用例的预期结果必须有对应的断言。
- 测试用例必须填写用例等级。
- 测试体建议按照模板分步实现。
- 用例描述信息按照标准格式@tc.xxx value书写,注释信息必须包含用例名称,用例描述,用例类型,需求编号四项。其中用例测试类型@tc.type参数的选取,可参考下表。
| 测试类型名称 | 类型编码 |
| ------------ | -------- |
| 功能测试 | FUNC |
| 性能测试 | PERF |
| 可靠性测试 | RELI |
| 安全测试 | SECU |
| 模糊测试 | FUZZ |
**TDD测试(JavaScript)**
-
用例源文件命名规范
-
用例源文件命名规范
测试用例原文件名称采用大驼峰风格,以TEST结尾,具体格式为:
[
功能
][
子功能
]
TEST
,子功能支持向下细分。
测试用例原文件名称采用大驼峰风格,以Test结尾,具体格式为:[功能][子功能]Test
,子功能支持向下细分。
示例:
示例:
```
```
AppInfoTest.js
AppInfoTest.js
```
```
-
用例示例
-
用例示例
```
js
```js
/*
/*
* Copyright (C) 2021
XXXX Device Co., Ltd.
* Copyright (C) 2023
XXXX Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* You may obtain a copy of the License at
...
@@ -351,11 +485,11 @@ AppInfoTest.js
...
@@ -351,11 +485,11 @@ AppInfoTest.js
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
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'
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
console.info('beforeAll caled')
console.info('beforeAll caled')
...
@@ -389,13 +523,13 @@ describe("AppInfoTest", function () {
...
@@ -389,13 +523,13 @@ describe("AppInfoTest", function () {
//Step 2:使用断言比较预期与实际结果
//Step 2:使用断言比较预期与实际结果
expect(info != null).assertEqual(true)
expect(info != null).assertEqual(true)
})
})
})
})
```
```
详细内容介绍:
详细内容介绍:
1.
添加测试用例文件头注释信息
1. 添加测试用例文件头注释信息
```
```
/*
/*
* Copyright (C) 2021
XXXX Device Co., Ltd.
* Copyright (C) 2023
XXXX Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* You may obtain a copy of the License at
...
@@ -409,13 +543,13 @@ describe("AppInfoTest", function () {
...
@@ -409,13 +543,13 @@ describe("AppInfoTest", function () {
* limitations under the License.
* limitations under the License.
*/
*/
```
```
2. 导入被测api和jsunit测试库
2. 导入被测api和jsunit测试库
```js
```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
```js
describe("AppInfoTest", function () {
describe("AppInfoTest", function () {
beforeAll(function() {
beforeAll(function() {
...
@@ -438,7 +572,7 @@ describe("AppInfoTest", function () {
...
@@ -438,7 +572,7 @@ describe("AppInfoTest", function () {
console.info('afterEach caled')
console.info('afterEach caled')
})
})
```
```
4.
测试用例实现
4. 测试用例实现
```JS
```JS
/*
/*
* @tc.name:appInfoTest001
* @tc.name:appInfoTest001
...
@@ -454,11 +588,11 @@ describe("AppInfoTest", function () {
...
@@ -454,11 +588,11 @@ describe("AppInfoTest", function () {
expect(info != null).assertEqual(true)
expect(info != null).assertEqual(true)
})
})
```
```
> **注意:** @tc.require: 格式必须以issue开头: 如:issueI56WJ7
> **注意:** @tc.require的取值必须以AR/SR或issue开头,如:issueI56WJ7。
**Fuzz测试**
**Fuzz
ing安全
测试**
[Fuzz用例编写规范](https://gitee.com/openharmony/testfwk_developer_test/blob/master/libs/fuzzlib/README_zh.md)
[
Fuzz
ing安全测试
用例编写规范
](
https://gitee.com/openharmony/testfwk_developer_test/blob/master/libs/fuzzlib/README_zh.md
)
**Benchmark测试**
**Benchmark测试**
...
@@ -475,20 +609,20 @@ describe("AppInfoTest", function () {
...
@@ -475,20 +609,20 @@ describe("AppInfoTest", function () {
-
**C++用例编译配置示例**
-
**C++用例编译配置示例**
```
```
# Copyright (c) 2021
XXXX Device Co., Ltd.
# Copyright (c) 2023
XXXX Device Co., Ltd.
import("//build/test.gni")
import("//build/test.gni")
module_output_path = "developertest/calculator"
module_output_path = "developertest/calculator"
config("module_private_config") {
config("module_private_config") {
visibility = [ ":*" ]
visibility = [ ":*" ]
include_dirs = [ "../../../include" ]
include_dirs = [ "../../../include" ]
}
}
ohos_unittest("CalculatorSubTest") {
ohos_unittest("CalculatorSubTest") {
module_out_path = module_output_path
module_out_path = module_output_path
sources = [
sources = [
...
@@ -501,30 +635,32 @@ ohos_unittest("CalculatorSubTest") {
...
@@ -501,30 +635,32 @@ ohos_unittest("CalculatorSubTest") {
configs = [ ":module_private_config" ]
configs = [ ":module_private_config" ]
deps = [ "//third_party/googletest:gtest_main" ]
deps = [ "//third_party/googletest:gtest_main" ]
}
}
group("unittest") {
group("unittest") {
testonly = true
testonly = true
deps = [":CalculatorSubTest"]
deps = [":CalculatorSubTest"]
}
}
```
```
详细内容如下:
详细内容如下:
1. 添加文件头注释信息
1. 添加文件头注释信息
```
```
# Copyright (c) 2021
XXXX Device Co., Ltd.
# Copyright (c) 2023
XXXX Device Co., Ltd.
```
```
2. 导入编译模板文件
2. 导入编译模板文件
```
```
import("//build/test.gni")
import("//build/test.gni")
```
```
3.
指定文件输出路径
3. 指定文件输出路径
```
```
module_output_path = "developertest/calculator"
module_output_path = "developertest/calculator"
```
```
> **说明:** 此处输出路径为部件/模块名。
>  **说明:**
>
> 此处输出路径为部件/模块名。
4.
配置依赖包含目录
4. 配置依赖包含目录
```
```
config("module_private_config") {
config("module_private_config") {
...
@@ -533,15 +669,17 @@ group("unittest") {
...
@@ -533,15 +669,17 @@ group("unittest") {
include_dirs = [ "../../../include" ]
include_dirs = [ "../../../include" ]
}
}
```
```
> **说明:** 一般在此处对相关配置进行设置,在测试用例编译脚本中可直接引用。
>  **说明:**
>
> 一般在此处对相关配置进行设置,在测试用例编译脚本中可直接引用。
5.
指定测试用例编译目标输出的文件名称
5. 指定测试用例编译目标输出的文件名称
```
```
ohos_unittest("CalculatorSubTest") {
ohos_unittest("CalculatorSubTest") {
}
}
```
```
6.
编写具体的测试用例编译脚本(添加需要参与编译的源文件、配置和依赖)
6. 编写具体的测试用例编译脚本(添加需要参与编译的源文件、配置和依赖)
```
```
ohos_unittest("CalculatorSubTest") {
ohos_unittest("CalculatorSubTest") {
module_out_path = module_output_path
module_out_path = module_output_path
...
@@ -556,7 +694,9 @@ group("unittest") {
...
@@ -556,7 +694,9 @@ group("unittest") {
}
}
```
```
> **说明:根据测试类型的不同,在具体编写过程中可选择不同的测试类型:**
>  **说明:**
>
> 根据测试类型的不同,在具体编写过程中可选择不同的测试类型。
> - ohos_unittest:单元测试
> - ohos_unittest:单元测试
> - ohos_moduletest:模块测试
> - ohos_moduletest:模块测试
> - ohos_systemtest:系统测试
> - ohos_systemtest:系统测试
...
@@ -565,7 +705,7 @@ group("unittest") {
...
@@ -565,7 +705,7 @@ group("unittest") {
> - ohos_reliabilitytest:可靠性测试
> - ohos_reliabilitytest:可靠性测试
> - ohos_distributedtest:分布式测试
> - ohos_distributedtest:分布式测试
7.
对目标测试用例文件进行条件分组
7. 对目标测试用例文件进行条件分组
```
```
group("unittest") {
group("unittest") {
...
@@ -573,75 +713,80 @@ group("unittest") {
...
@@ -573,75 +713,80 @@ group("unittest") {
deps = [":CalculatorSubTest"]
deps = [":CalculatorSubTest"]
}
}
```
```
> **说明:** 进行条件分组的目的在于执行用例时可以选择性的执行某一种特定类型的用例。
>  **说明:**
>
> 进行条件分组的目的在于执行用例时可以选择性地执行某一种特定类型的用例。
-
**JavaScript用例编译配置示例**
-
**JavaScript用例编译配置示例**
```
```
# Copyright (C) 2021
XXXX Device Co., Ltd.
# Copyright (C) 2023
XXXX Device Co., Ltd.
import("//build/test.gni")
import("//build/test.gni")
module_output_path = "developertest/app_info"
module_output_path = "developertest/app_info"
ohos_js_unittest("GetAppInfoJsTest") {
ohos_js_unittest("GetAppInfoJsTest") {
module_out_path = module_output_path
module_out_path = module_output_path
hap_profile = "./config.json"
hap_profile = "./config.json"
certificate_profile = "//test/developertest/signature/openharmony_sx.p7b"
certificate_profile = "//test/developertest/signature/openharmony_sx.p7b"
}
}
group("unittest") {
group("unittest") {
testonly = true
testonly = true
deps = [ ":GetAppInfoJsTest" ]
deps = [ ":GetAppInfoJsTest" ]
}
}
```
```
详细内容如下:
详细内容如下:
1.
添加文件头注释信息
1.
添加文件头注释信息
```
```
# Copyright (C) 2021
XXXX Device Co., Ltd.
# Copyright (C) 2023
XXXX Device Co., Ltd.
```
```
2.
导入编译模板文件
2.
导入编译模板文件
```
```
import("//build/test.gni")
import("//build/test.gni")
```
```
3.
指定文件输出路径
3.
指定文件输出路径
```
```
module_output_path = "developertest/app_info"
module_output_path = "developertest/app_info"
```
```
> **说明:** 此处输出路径为部件/模块名。
>  **说明:**
>
> 此处输出路径为部件/模块名。
4.
指定测试用例编译目标输出的文件名称
4.
指定测试用例编译目标输出的文件名称
```
```
ohos_js_unittest("GetAppInfoJsTest") {
ohos_js_unittest("GetAppInfoJsTest") {
}
}
```
```
> **说明:**
>  **说明:**
> - 使用模板ohos_js_unittest定义js测试套,注意与C++用例区分。
>
> - js测试套编译输出文件为hap类型,hap名为此处定义的测试套名,测试套名称必须以JsTest结尾。
> - 使用模板ohos_js_unittest定义js测试套,注意与C++用例区分。
> - js测试套编译输出文件为hap类型,hap名为此处定义的测试套名,测试套名称必须以JsTest结尾。
5.
指定hap包配置文件config.json和签名文件,两个配置为必选项
5. 指定hap包配置文件config.json和签名文件,两个配置为必选项。
```
```
ohos_js_unittest("GetAppInfoJsTest") {
ohos_js_unittest("GetAppInfoJsTest") {
module_out_path = module_output_path
module_out_path = module_output_path
hap_profile = "./config.json"
hap_profile = "./config.json"
certificate_profile = "//test/developertest/signature/openharmony_sx.p7b"
certificate_profile = "//test/developertest/signature/openharmony_sx.p7b"
}
}
```
```
config.json为hap编译所需配置文件,需要开发者根据被测sdk版本配置“target”项,其余项可默认,具体如下所示:
config.json为hap编译所需配置文件,需要开发者根据被测sdk版本配置“target”项,其余项可默认,具体如下所示:
```
json
```json
{
{
"app": {
"app": {
"bundleName": "com.example.myapplication",
"bundleName": "com.example.myapplication",
"vendor": "example",
"vendor": "example",
...
@@ -700,97 +845,108 @@ ohos_js_unittest("GetAppInfoJsTest") {
...
@@ -700,97 +845,108 @@ ohos_js_unittest("GetAppInfoJsTest") {
]
]
}
}
}
}
```
```
6.
对目标测试用例文件进行条件分组
6.
对目标测试用例文件进行条件分组
```
```
group("unittest") {
group("unittest") {
testonly = true
testonly = true
deps = [ ":GetAppInfoJsTest" ]
deps = [ ":GetAppInfoJsTest" ]
}
}
```
```
> **说明:** 进行条件分组的目的在于执行用例时可以选择性的执行某一种特定类型的用例。
>  **说明:**
>
> 进行条件分组的目的在于执行用例时可以选择性地执行某一种特定类型的用例。
**Fuzz测试**
**Fuzz
ing安全
测试**
[
Fuzz
编译文件
编写规范
](
https://gitee.com/openharmony/test_developertest/blob/master/libs/fuzzlib/README_zh.md
)
[
Fuzz
ing安全测试编译文件的
编写规范
](
https://gitee.com/openharmony/test_developertest/blob/master/libs/fuzzlib/README_zh.md
)
**Benchmark测试**
**Benchmark测试**
[
Benchmark编译文件编写规范
](
https://gitee.com/openharmony/test_developertest/blob/master/libs/benchmark/README_zh.md
)
[
Benchmark编译文件编写规范
](
https://gitee.com/openharmony/test_developertest/blob/master/libs/benchmark/README_zh.md
)
**编译入口配置文件
ohos.build
**
**编译入口配置文件
bundle.json
**
当完成用例编译配置文件编写后,需要进一步编写部件编译配置文件,以关联到具体的测试用例。
当完成用例编译配置文件编写后,需要进一步编写部件编译配置文件,以关联到具体的测试用例。
```
```
"partA": {
"build": {
"module_list": [
"sub_component": [
"//test/testfwk/developer_test/examples/app_info:app_info",
"//test/testfwk/developer_test/examples/detector:detector",
"//test/testfwk/developer_test/examples/calculator:calculator"
],
],
"inner_list": [
"inner_list": [
{
],
"header": {
"system_kits": [
"header_base": "////test/testfwk/developer_test/examples/detector/include",
"header_files": [
"detector.h"
]
},
"name": "//test/testfwk/developer_test/examples/detector:detector"
}
],
],
"test
_list
": [ //配置模块calculator下的test
"test": [ //配置模块calculator下的test
"//
system/subsystem/partA/calculator
/test:unittest",
"//
test/testfwk/developer_test/examples/app_info
/test:unittest",
"//
system/subsystem/partA/calculator/test:fuzz
test",
"//
test/testfwk/developer_test/examples/calculator/test:unit
test",
"//
system/subsystem/partA/calculator/test:benchmark
test"
"//
test/testfwk/developer_test/examples/calculator/test:fuzz
test"
}
}
```
```
> **说明:** test_list中配置的是对应模块的测试用例。
>  **说明:**
>
> test_list中配置的是对应模块的测试用例。
##
测试资源配置
##
配置测试资源
试依赖资源主要包括测试用例在执行过程中需要的图片文件,视频文件、第三方库等对外的文件资源
。
测试依赖资源主要包括测试用例在执行过程中需要的图片文件、视频文件、第三方库等对外的文件资源,目前只支持静态资源的配置
。
依赖资源文件配置步骤如下:
依赖资源文件配置步骤如下:
1.
在部件的test目录下创建resource目录,在resource目录下创建对应的模块,在模块目录中存放该模块所需要的资源文件
1.
在部件的test目录下创建resource目录,在resource目录下创建对应的模块,在模块目录中存放该模块所需要的资源文件。
2.
在resource目录下对应的模块目录中创建一个ohos_test.xml文件,文件内容格式如下:
2.
在resource目录下对应的模块目录中创建一个ohos_test.xml文件,文件内容格式如下:
```
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">
<preparer>
<preparer>
<option name="push" value="test.jpg -> /data/test/resource" src="res"/>
<option name="push" value="test.jpg -> /data/test/resource" src="res"/>
<option name="push" value="libc++.z.so -> /data/test/resource" src="out"/>
<option name="push" value="libc++.z.so -> /data/test/resource" src="out"/>
</preparer>
</preparer>
</target>
</target>
</configuration>
</configuration>
```
```
3.
在测试用例的编译配置文件中定义resource_config_file进行指引,用来指定对应的资源文件ohos_test.xml
3.
在测试用例的编译配置文件中定义resource_config_file进行指引,用来指定对应的资源文件ohos_test.xml。
```
```
ohos_unittest("CalculatorSubTest") {
ohos_unittest("CalculatorSubTest") {
resource_config_file = "//system/subsystem/partA/test/resource/calculator/ohos_test.xml"
resource_config_file = "//system/subsystem/partA/test/resource/calculator/ohos_test.xml"
}
}
```
```
>**说明:**
>  **说明:**
>- target_name: 测试套的名称,定义在测试目录的BUILD.gn中。preparer: 表示该测试套执行前执行的动作。
>
>- src="res": 表示测试资源位于test目录下的resource目录下,src="out":表示位于out/release/$(部件)目录下。
>- target_name: 测试套的名称,定义在测试目录的BUILD.gn中。preparer: 表示该测试套执行前执行的动作。
>- src="res": 表示测试资源位于test目录下的resource目录下,src="out":表示位于out/release/$(部件)目录下。
## 执行测试用例
## 执行测试用例
###
配置文件
###
user_config.xml配置文件介绍
在执行测试用例之前,针对用例使用设备的不同,需要对相应配置进行修改,修改完成即可执行测试用例。
在执行测试用例之前,针对用例使用设备的不同,需要对相应配置进行修改,
配置文件路径为developer_test
\c
onfig
\u
ser_config.xml,
修改完成即可执行测试用例。
#### user_config.xml配置
```
xml
```
xml
<user_config>
<user_config>
<build>
<build>
<!-- 是否编译demo用例
,
默认为false,如果需要编译demo可修改为true -->
<!-- 是否编译demo用例
,
默认为false,如果需要编译demo可修改为true -->
<example>
false
</example>
<example>
false
</example>
<!-- 是否编译版本
,
默认为false -->
<!-- 是否编译版本
,
默认为false -->
<version>
false
</version>
<version>
false
</version>
<!-- 是否编译测试用例
,
默认为true,若已完成编译,再执行用例之前可修改为false,防止重新编译 -->
<!-- 是否编译测试用例
,
默认为true,若已完成编译,再执行用例之前可修改为false,防止重新编译 -->
<testcase>
true
</testcase>
<testcase>
true
</testcase>
<!-- 在编译测试用例的情况下,选择编译target_cpu是64位的还是32位的,默认为空(32bit)可以选择: arm64 -->
<!-- 在编译测试用例的情况下,选择编译target_cpu是64位的还是32位的,默认为空(32bit)可以选择: arm64 -->
<parameter>
<parameter>
...
@@ -832,54 +988,33 @@ ohos_unittest("CalculatorSubTest") {
...
@@ -832,54 +988,33 @@ ohos_unittest("CalculatorSubTest") {
</NFS>
</NFS>
</user_config>
</user_config>
```
```
>
**说明:** 在执行测试用例之前,若使用HDC连接设备,用例仅需配置设备IP和端口号即可,其余信息均默认不修改。
>
 **说明:**
>
### 执行命令说明
> 在执行测试用例之前,若使用HDC连接设备,用例仅需配置设备IP和端口号即可,其余信息均默认不修改。
1.
启动测试框架
### Windows环境执行
```
#### 编译测试用例
start.bat
```
2.
选择产品形态
进入测试框架,系统会自动提示您选择产品形态,请根据实际的开发板进行选择。
如需手动添加,请在config/framework_config.xml的\<productform\>标签内增加产品项。
3.
执行测试用例
当选择完产品形态,可参考如下指令执行测试用例。
```
run -t UT -ts CalculatorSubTest -tc interger_sub_00l
```
执行命令参数说明:
```
-t [TESTTYPE]: 指定测试用例类型,有UT,MST,ST,PERF,FUZZ,BENCHMARK等。(必选参数)
-tp [TESTPART]: 指定部件,可独立使用。
-tm [TESTMODULE]: 指定模块,不可独立使用,需结合-tp指定上级部件使用。
-ts [TESTSUITE]: 指定测试套,可独立使用。
-tc [TESTCASE]: 指定测试用例,不可独立使用,需结合-ts指定上级测试套使用。
-h : 帮助命令。
#### Windows环境执行
由于Windows环境下无法实现用例编译,因此执行用例前需要在Linux环境下进行用例编译,用例编译命令:
由于Windows环境下无法实现用例编译,因此执行用例前需要在Linux环境下进行用例编译,用例编译命令:
```
```
./build.sh --product-name {product_name} --build-target make_test
./build.sh --product-name {product_name} --build-target make_test
```
```
>说明:
>  **说明:**
>
>- product-name:指定编译产品名称。
>- product-name:指定编译产品名称。
>- build-target:指定所需编译用例,make_test表示指定全部用例,实际开发中可指定特定用例。
>- build-target:指定所需编译用例,make_test表示指定全部用例,实际开发中可指定特定用例。
编译完成后,测试用例将自动保存在out/ohos-arm-release/packages/phone/tests目录下。
编译完成后,测试用例将自动保存在out/ohos-arm-release/packages/phone/tests目录下。
####
#
搭建执行环境
#### 搭建执行环境
1.
在Windows环境创建测试框架目录Test,并在此目录下创建testcase目录
1.
在Windows环境创建测试框架目录Test,并在此目录下创建testcase目录
。
2.
从Linux环境拷贝测试框架developertest和xdevice到创建的Test目录下,拷贝编译好的测试用例到testcase目录下
2.
从Linux环境拷贝测试框架developertest和xdevice到创建的Test目录下,拷贝编译好的测试用例到testcase目录下
。
>**说明:** 将测试框架及测试用例从Linux环境移植到Windows环境,以便后续执行。
>  **说明:**
>
> 将测试框架及测试用例从Linux环境移植到Windows环境,以便后续执行。
3.
修改user_config.xml
3.
修改user_config.xml
```
xml
```
xml
...
@@ -892,39 +1027,215 @@ ohos_unittest("CalculatorSubTest") {
...
@@ -892,39 +1027,215 @@ ohos_unittest("CalculatorSubTest") {
<dir>
D:\Test\testcase\tests
</dir>
<dir>
D:\Test\testcase\tests
</dir>
</test_cases>
</test_cases>
```
```
>**说明:** `<testcase>`标签表示是否需要编译用例;`<dir>`标签表示测试用例查找路径。
>  **说明:**
>
> `<testcase>`标签表示是否需要编译用例;`<dir>`标签表示测试用例查找路径。
#### 执行用例命令
1.
启动测试框架
```
start.bat
```
2.
选择产品形态
进入测试框架,系统会自动提示您选择产品形态,请根据实际的开发板进行选择。
如需手动添加,请在config/framework_config.xml的\<productform\>标签内增加产品项。
3.
执行测试用例
当选择完产品形态,可参考如下指令执行TDD测试用例。
```
run -t UT
run -t UT -tp PartName
run -t UT -tp PartName -tm TestModuleName
run -t UT -tp ability_base -ts base_object_test
run -t UT -tp PartName -tm TestModuleName -ts CalculatorSubTest
run -t UT -ts base_object_test
run -t UT -ts base_object_test -tc AAFwkBaseObjectTest.BaseObject_test_001
run -t UT -ts CalculatorSubTest -tc CalculatorSubTest.interger_sub_00l
run -t UT -cov coverage
run -t UT -ra random
run -t UT -ts base_object_test --repeat 5
run -hl
run -rh 3
run --retry
```
执行命令参数说明:
```
-t [TESTTYPE]: 指定测试用例类型,有UT,MST,ST,PERF,FUZZ,BENCHMARK,另外还有ACTS,HATS等。(必选参数)
-tp [TESTPART]: 指定部件,可独立使用。
-tm [TESTMODULE]: 指定模块,不可独立使用,需结合-tp指定上级部件使用。
-ts [TESTSUITE]: 指定测试套,可独立使用。
-tc [TESTCASE]: 指定测试用例,同时需要注明测试套内class名称,不可独立使用,需结合-ts指定上级测试套使用。
-cov [COVERAGE]: 覆盖率执行参数。
-h : 帮助命令
-ra [random]: c++用例乱序执行参数。
--repeat : 支持设置用例执行次数。
-hl [HISTORYLIST]: 显示最近10条测试用例,超过10条,只显示最近10条。
-rh [RUNHISTORY]: 执行历史记录的第几条记录运行。
--retry:检查上次运行结果,如果有失败用例则重复测试。
```
###
#
Linux环境执行
### Linux环境执行
如是直接连接Linux机器,则可直接使用上面的执行命令执行命令
####
# 远程端口映射
####
映射远程端口及修改配置文件
为支持Linux远程服务器以及Linux虚拟机两种环境下执行测试用例,需要对端口进行远程映射,以实现与设备的数据通路连接。具体操作如下:
为支持Linux远程服务器以及Linux虚拟机两种环境下执行测试用例,需要对端口进行远程映射,以实现与设备的数据通路连接。具体操作如下:
1.
HDC Server指令:
1.
HDC Server指令:
```
```
hdc_std kill
hdc_std kill
hdc_std -m -s 0.0.0.0:8710
hdc_std -m -s 0.0.0.0:8710
```
```
>**说明:** IP和端口号为默认值。
>  **说明:**
>
> IP和端口号为默认值。
2.
HDC Client指令:
2.
HDC Client指令:
```
```
hdc_std -s xx.xx.xx.xx:8710 list targets
hdc_std -s xx.xx.xx.xx:8710 list targets
```
```
>**说明:** 此处IP填写设备侧IP地址。
>  **说明:**
>
> 此处IP填写设备侧IP地址。
3.
修改配置文件user_config.xml
```
xml
<build>
<!-- 测试用例需要编译时,此标签属性为true,反之为false -->
<testcase>
true
</testcase>
</build>
<environment>
<!-- 需要配置IP为远程映射机器的IP,端口即为8710,sn号为设备的sn号,以支持HDC连接的设备 -->
<device
type=
"usb-hdc"
>
<ip></ip>
<port></port>
<sn></sn>
</device>
<environment>
```
#### 执行用例命令
1.
启动测试框架
```
./start.sh
```
2.
选择产品形态
进入测试框架,系统会自动提示您选择产品形态,请根据实际的开发板进行选择。
若需要自测试框架编译测试用例,且没有找到需要的产品形态需手动添加,请在config/framework_config.xml的\<productform\>标签内增加产品项。
```
<framework_config>
<productform>
<option name="ipcamera_hispark_aries" />
<option name="ipcamera_hispark_taurus" />
<option name="wifiiot_hispark_pegasus" />
<option name="" />
</productform>
</framework_config>
```
3.
执行测试用例
1) TDD命令
测试框架在执行用例时会根据指令找到所需用例,自动实现用例编译,执行过程,完成自动化测试。
```
run -t UT
run -t UT -tp PartName
run -t UT -tp PartName -tm TestModuleName
run -t UT -tp ability_base -ts base_object_test
run -t UT -tp PartName -tm TestModuleName -ts CalculatorSubTest
run -t UT -ts base_object_test
run -t UT -ts base_object_test -tc AAFwkBaseObjectTest.BaseObject_test_001
run -t UT -ts CalculatorSubTest -tc CalculatorSubTest.interger_sub_00l
run -t -cov coverage
run -t UT -ra random
run -t UT -tp PartName -pd partdeps
run -t UT -ts base_object_test --repeat 5
run -hl
run -rh 3
run --retry
```
执行命令参数说明:
```
-t [TESTTYPE]: 指定测试用例类型(必选参数),有UT,MST,ST,PERF,FUZZ,BENCHMARK等。
-tp [TESTPART]: 指定部件,可独立使用。
-tm [TESTMODULE]: 指定模块,不可独立使用,需结合-tp指定上级部件使用。
-ts [TESTSUITE]: 指定测试套,可独立使用。
-tc [TESTCASE]: 指定测试用例,同时需要注明测试套内class名称,不可独立使用,需结合-ts指定上级测试套使用。
-cov [COVERAGE]: 覆盖率执行参数。
-h : 帮助命令
-ra [random]: c++用例乱序执行参数
-pd [partdeps]: 二级依赖部件执行参数
--repeat : 支持设置用例执行次数。
-hl [HISTORYLIST]: 显示最近10条测试用例,超过10条,只显示最近10条。
-rh [RUNHISTORY]: 执行历史记录的第几条记录运行。
--retry:检查上次运行结果,如果有失败用例则重复测试。
```
在Linux下可以使用help命令查看有哪些产品形态、测试类型、支持的子系统、部件。
```
查看帮助命令:help
查看show命令:help show
查看支持的设备形态: show productlist
查看支持的测试类型: show typelist
查看支持的测试子系统: show subsystemlist
查看支持的测试部件: show partlist
```
2) ACTS/HATS命令
当选择完产品形态,可以参考如下执行ACTS或HATS测试用例。
```
run -t ACTS
run -t HATS
run -t ACTS -ss arkui
run -t ACTS -ss arkui, modulemanager
run -t ACTS -ss arkui -ts ActsAceEtsTest
run -t HATS -ss telephony -ts HatsHdfV1RilServiceTest
run -t ACTS -ss arkui -tp ActsPartName
run -t ACTS -ss arkui -ts ActsAceEtsTest,ActsAceEtsResultTest
run -t HATS -ss powermgr -ts HatsPowermgrBatteryTest,HatsPowermgrThermalTest
run -t ACTS -ss arkui -ts ActsAceEtsTest -ta class:alphabetIndexerTest#alphabetIndexerTest001
run -t ACTS -ss arkui -ts ActsAceEtsTest -ta class:alphabetIndexerTest#alphabetIndexerTest001 --repeat 2
run -hl
run -rh 1
run --retry
```
执行命令参数说明,ACTS和HATS命令参数一致,与TDD有所不同:
```
-t [TESTTYPE]: 指定测试用例类型(必选参数),有ACTS,HATS等。
-ss [SUBSYSTEM]: 指定子系统,可单独使用,且可以执行多个子系统,用逗号隔开。
-tp [TESTPART]: 指定部件,可独立使用。
-ts [TESTSUITE]: 指定测试套,可独立使用,且可以执行多个测试套,用逗号隔开。
-ta [TESTARGS]: 指定测试类测试方法,需结合-ts指定上级测试套使用。
--repeat : 支持设置用例执行次数。
-hl [HISTORYLIST]: 显示最近10条测试用例,超过10条,只显示最近10条。
-rh [RUNHISTORY]: 执行历史记录的第几条记录运行。
--retry:检查上次运行结果,如果有失败用例则重复测试。
```
## 查看测试结果
## 查看测试结果
### 测试报告日志
当执行完测试指令,控制台会自动生成测试结果,若需要详细测试报告
您可在相应的数据文档中进行查找
。
当执行完测试指令,控制台会自动生成测试结果,若需要详细测试报告
,您可在以下路径中进行查找相应的数据文档
。
### 测试结果
### 测试结果
测试结果输出根路径如下:
测试结果输出根路径如下:
```
```
test/developertest/reports/xxxx_xx_xx_xx_xx_xx
test/developertest/reports/xxxx_xx_xx_xx_xx_xx
```
```
>**说明:** 测试报告文件目录将自动生成。
>  **说明:**
>
> 测试报告文件目录将自动生成。
该目录中包含以下几类结果:
该目录中包含以下几类结果:
| 类型 | 描述 |
| 类型 | 描述 |
...
@@ -934,10 +1245,7 @@ test/developertest/reports/xxxx_xx_xx_xx_xx_xx
...
@@ -934,10 +1245,7 @@ test/developertest/reports/xxxx_xx_xx_xx_xx_xx
| summary_report.html | 测试报告汇总 |
| summary_report.html | 测试报告汇总 |
| details_report.html | 测试报告详情 |
| details_report.html | 测试报告详情 |
### 测试框架日志
```
reports/platform_log_xxxx_xx_xx_xx_xx_xx.log
```
### 最新测试报告
### 最新测试报告
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录