The 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.
This subsystem contains the ACTS and tools software package.
OpenHarmony supports the following system types:
Mini system
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.
Small system
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.
Standard system
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.
/test/xts
├── acts # Test code
│ └── subsystem # Source code of subsystem test cases for the standard system
│ └── subsystem_lite # Source code of subsystems test cases for mini and small systems
│ └── BUILD.gn # Build configuration of test cases for the standard system
│ └── build_lite
│ └── BUILD.gn # Build configuration of test cases for mini and small systems
└── tools # Test tool code
Test cases for the mini system must be developed based on C, and those for the small system must be developed based on C++.
Table 1 Test case levels
Table 2 Test case granularities
Table 3 Test types
You should select the appropriate programming language and your target test framework to develop test cases.
Table 4 Test frameworks and test case languages for different systems
Developing test cases for the mini system
The 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.
Access the test/xts/acts repository where the test cases will be stored.
├── acts
│ └──subsystem_lite
│ │ └── module_hal
│ │ │ └── BUILD.gn
│ │ │ └── src
│ └──build_lite
│ │ └── BUILD.gn
Write the test case in the src directory.
1 Import the test framework header file.
#include "hctest.h"
/**
* @brief Registers a test suite named IntTestSuite.
* @param test Subsystem name
* @param example Module name
* @param IntTestSuite Test suite name
*/
LITE_TEST_SUIT(test, example, IntTestSuite);
Format: Test suite name+Setup, Test suite name+TearDown.
The Setup and TearDown functions must exist, but function bodies can be empty.
Three parameters are involved: test suite name, test case name, and test case properties (including type, granularity, and level).
LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1)
{
// Do something
};
RUN_TEST_SUITE(IntTestSuite);
Create the configuration file (BUILD.gn) of the test module.
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:
import("//test/xts/tools/lite/build/suite_lite.gni")
hctest_suite("ActsDemoTest") {
suite_name = "acts"
sources = [
"src/test_demo.c",
]
include_dirs = [ ]
cflags = [ "-Wno-error" ]
}
Add build options to the BUILD.gn file in the acts directory.
You need to add the test module to the test/xts/acts/build_lite/BUILD.gn script in the acts directory.
lite_component("acts") {
...
if(board_name == "liteos_m") {
features += [
...
"//xts/acts/subsystem_lite/module_hal:ActsDemoTest"
]
}
}
Run build commands.
Test suites are built along with version build. The ACTS is built together with the debug version.
NOTE: The ACTS build middleware is a static library, which will be linked to the image.
Executing test cases for the mini system
Burn the image into the development board.
Executing the test
Analyzing the test result
View the serial port logs, whose format is as follows:
The log for each test suite starts with Start to run test suite: and ends with xx Tests xx Failures xx Ignored.
Developing test cases for small-system devices (For examples of the standard system, go to the global/i18n_standard directory.)
The HCPPTest framework is enhanced and adapted based on the open-source framework Googletest.
Access the test/xts/acts repository where the test cases will be stored.
├── acts
│ └──subsystem_lite
│ │ └── module_posix
│ │ │ └── BUILD.gn
│ │ │ └── src
│ └──build_lite
│ │ └── BUILD.gn
Write the test case in the src directory.
The following statement includes gtest.h.
#include "gtest/gtest.h"
using namespace std;
using namespace testing::ext;
class TestSuite: public testing::Test {
protected:
// Preset action of the test suite, which is executed before the first test case
static void SetUpTestCase(void){
}
// Test suite cleanup action, which is executed after the last test case
static void TearDownTestCase(void){
}
// Preset action of the test case
virtual void SetUp()
{
}
// Cleanup action of the test case
virtual void TearDown()
{
}
};
HWTEST: definition of common test cases, including the test suite name, test case name, and case annotation.
HWTEST_F: definition of SetUp and TearDown test cases, including the test suite name, test case name, and case annotation.
Three parameters are involved: test suite name, test case name, and test case properties (including type, granularity, and level).
HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) {
// Do something
}
Create a configuration file (BUILD.gn) of the test module.
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.
Example:
import("//test/xts/tools/lite/build/suite_lite.gni")
hcpptest_suite("ActsDemoTest") {
suite_name = "acts"
sources = [
"src/TestDemo.cpp"
]
include_dirs = [
"src",
...
]
deps = [
...
]
cflags = [ "-Wno-error" ]
}
Add build options to the BUILD.gn file in the acts directory.
Add the test module to the test/xts/acts/build_lite/BUILD.gn script in the acts directory.
lite_component("acts") {
...
else if(board_name == "liteos_a") {
features += [
...
"//xts/acts/subsystem_lite/module_posix:ActsDemoTest"
]
}
}
Run build commands.
Test suites are built along with the version build. The ACTS is built together with the debug version.
NOTE: 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.
Executing test cases for the small system
Currently, test cases are shared by the NFS and mounted to the development board for execution.
Setting up the environment
Use a network cable or wireless network to connect the development board to your PC.
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.
Install and register the NFS server on the PC and start the NFS service.
Run the mount command for the development board to ensure that the development board can access NFS shared files on the PC.
Format: mount NFS server IP address:/NFS shared directory /development board directory nfs
Example:
mount 192.168.1.10:/nfs /nfs nfs
Executing test cases
Execute ActsDemoTest.bin to trigger test case execution, and analyze serial port logs generated after the execution is complete.
The HJSUnit framework is used to support automated test of OpenHarmony apps that are developed using the JavaScript language based on the JS application framework.
Basic syntax of test cases
The test cases are developed with the JavaScript language and must meet the programming specifications of the language.
Table 5
Use the standard syntax of Jasmine to write test cases. The ES6 specification is supported.
Store the test cases in the entry/src/main/js/test directory, whose structure is as follows:
├── BUILD.gn
│ └──entry
│ │ └──src
│ │ │ └──main
│ │ │ │ └──js
│ │ │ │ │ └──default
│ │ │ │ │ │ └──pages
│ │ │ │ │ │ │ └──index
│ │ │ │ │ │ │ │ └──index.js # Entry file
│ │ │ │ │ └──test # Test code
│ │ │ └── resources # HAP resources
│ │ │ └── config.json # HAP configuration file
Start the JS test framework and load test cases. The following is an example for index.js.
// Start the JS test framework and load test cases.
import {Core, ExpectExtend} from 'deccjsunit/index'
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
require('../../../test/List.test')
core.execute()
},
onReady() {
},
}
Write a unit test case by referring to the following example:
// Use HJSUnit to perform the unit test.
describe('appInfoTest', function () {
it('app_info_test_001', 0, function () {
var info = app.getInfo()
expect(info.versionName).assertEqual('1.0')
expect(info.versionCode).assertEqual('3')
})
})
For details about how to build a HAP, see the JS application development guide of the standard system Building and Creating HAPs.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. Open source ecosystem
2. Collaboration, People, Software
3. Evaluation model