How to participate in open source contributions gracefully, submit PR (Pull Request) to top open source projects, and become an OpenAtom OpenHarmony (hereinafter referred to as "OpenHarmony") Contributor for 30 minutes with a big coffee. In the sixth phase of the "Code" Pioneer Live Room, Huawei OpenHarmony senior test engineer Andy, who has 10 years of experience in terminal product software and system framework testing, was invited to share with you "Building a Test Subsystem to Empower Developers to Improve Code Quality". In his sharing, he introduced: test subsystem, test infrastructure, stability test tool design, compatibility test suite examples and rapid participation in co-construction.
Participate in the battle "code" pioneer, PR solicitation order! You can submit PRs in Gitee's OpenHarmony code repository to participate in activities, compete with global developers, compete skills, and contribute to OpenHarmony.

Introduction to Test Subsystems

In the early stage of OpenHarmony system construction, each subsystem provides the basic capabilities of the system. To carry out the complete care of the subsystem, the workload of manual testing and verification is huge, and based on this, there is a demand for automated testing. The testing subsystem includes several parts of testing basic framework, OS testing standards and tools, application testing standards and tools, and compatibility testing. The subsequent official unified publicity name of the OpenHarmony test toolset is OpenHarmony Arsenal (OHA).
In the testing basic framework, the unit testing framework serves as the base of the testing basic framework to support the running of automated tests; the UI testing framework builds the ability of UI interface operation automated testing based on the unit testing framework; distributed testing components and special testing components serve as extension capabilities Evolve step by step; the test scheduling framework (xdevice) is responsible for the execution scheduling of the entire test script.
OS testing standards and tools: Mainly conduct DFX testing and verification of system stability, performance, and security, and find key issues such as abnormal system restarts and substandard frame rates. Application test standards and tools: Provide developers with test tools for DFX test verification of applications. Compatibility test: Provide compatibility test suites for north-south frame compatibility care.

Unit testing framework:

The unit testing framework provides basic test scripting, management, scheduling execution and report generation capabilities. The unit test framework relies on AbilityDelegator (the entry point of the test framework) and TestRunner (rewritten for test preparation and execution).
Core features include:
● Test suite & test case management: The test suite contains test cases, and the test cases are written and implemented based on the test suite ● Preset cleaning method: Each test case can be decoupled through preset and cleaning methods ● Configuration management: use case level and Type configuration management for subsequent screening of test execution cases Log processing capability: used for log statistics of test case execution results Basic assertion capability: Judgment of expected results and actual execution results of test cases Expansion capabilities:
● Defining execution order: used for subsequent configuration management of test case execution order ● Custom assertion: extended comparison capability based on basic assertion ● Asynchronous test & assertion: The test script performs asynchronous execution and assertion directly, currently it is executed through synchronous wait mode Empowerment:
● Data-driven: stress testing of the interface by configuring parameters ● Mock: simulate the implementation that depends on the external interface, and return the expected content ● Fake: directly return the expected return value that depends on the external interface, and the interface executes normally ● SPY: interface detection capability, verification Whether the interface is called and executed, you can refer to the specific code warehouse to understand the code logic of the unit testing framework.

A complete test suite execution process, start the test framework through the AA command line, the AMS framework pulls up the test process, starts TestRunner to parse the parameters, then starts TestAbility to load and execute the test case, print the execution result after the test case is executed, and close it. The test process and the AA process are completed, and the test suite is executed.

UI testing framework:

The UI testing framework provides UI interface testing capabilities, including basic capabilities such as UI operations and UI control inspection. The UI test framework will provide JS API for developers to use externally. UI Test provides the basic capabilities of the framework. The test framework relies on the accessibility service to obtain the control dump information of the interface, and the multi-modal input service provides the ability to operate the control. UI Test JS API includes ● Basic operation API: basic capabilities of clicking, sliding, etc. ● Control acquisition API: basic capabilities such as finding controls ● Enhanced operation API: control dragging, sliding to find controls, etc. ● Custom attribute API: sliding rate and button duration and other parameter configuration capabilities
UI Test: An independent process of UI Test, which provides data serialization capability, process keep-alive capability and event injection capability between test process and UI Test process. At present, it provides single-window UI automation testing, and then provides multi-window control operation capabilities, and actively recognizes UI interface changes and complex gesture operation capabilities such as multi-finger touch.
You can refer to the specific code warehouse to understand the code logic of the UI testing framework.

The core process of the UI testing framework: UI test case execution, starting the UITest process, binding accessibility services and multimodal services for interactive operations. Developers can write UI test scripts based on UIDriver, BY, and UIComponent classes.
You can refer to the specific code warehouse to understand the interface capabilities provided by the UI testing framework.

Code example of the new contact UI test script:

  1. Import dependent test packages
  2. Start the interface under test
  3. Initialize UIDriver
  4. Based on UIDriver's findComponent and BY capabilities to find contacts
  5. Click the contact control based on the click ability of UIComponent
  6. UIDriver-based assertComponentExist capability verification that there is no contact text

    Stability test tool design:

    The stability testing tool provides anomaly capture capabilities to help developers quickly identify system anomalies, and specify whether to test applications in the corresponding list through black and white lists. Provide recording and playback capabilities for auxiliary regression test verification. Currently, only event injection capabilities such as control operations are provided, and system event injection capabilities will be provided in the future. At present, the stability tool is preset in the version, and the visual device-side and PC-side test tools are provided in the future, so that developers can conduct stability tests more conveniently.
    You can refer to the specific code warehouse to understand the code logic of the stability testing tool framework.

    Stability tool execution example: wukong exec –b ohos.xxxx -a 0.1 -t 0.5 -S 0.4 -s 5
    Specific workflow: The stability test tool parses command line parameters, initializes the test environment, and starts exception monitoring. Stability testing is done through random event generation and event injection and cyclic processing of catching exceptions. Finally, log records are generated for viewing abnormal scenarios.
    Key command: A fixed sequence of operations can be specified through the seed seed for regression to reproduce the problem. Different events support scaling settings. The duration of the stability test can be specified through the time and count fields.

    Compatibility Test Suite:

    Compatibility care of the north-south direction of the application and east-west direction of the device is carried out through the compatibility test suite, and the compatibility is verified through the ACTS, DCTS, and HATS test suites respectively. You can refer to the code warehouse at the end of the article to understand the test case implementation of the compatibility test suite.

    The definition of the key syntax of the test case, the test suite is defined by describe, a test case must have 3 key annotation fields, tc.number: use case number, tc.name: use case name, tc.desc: use case description, test through it Use case definition.

    Quickly participate in co-construction:

    Finally, Andy introduced the way for developers to quickly participate in co-construction. Based on the API used in the development process, you can search for the test script of the corresponding API in the compatibility test code warehouse, identify the completeness of the current test case, and supplement and co-build the test script. The following two cases of the asynchronous interface of promise and callback are provided for the design of test scripts for normal and abnormal scenarios of the interface.

    Interested developers are welcome to build a test subsystem together and become an OpenHarmony Contributor. Participate in the battle "code" pioneer, PR solicitation order! Submit PR in Gitee's OpenHarmony code warehouse to participate in activities, and build a prosperous OpenHarmony ecosystem with developers around the world!
    "Open gitee now, mention your first PR, one small step for you, one giant leap for the OpenHarmony open source project"

    A summary of the links involved in the article:

    Unit test framework code warehouse jsunit directory:
    https://gitee.com/openharmony/arkXtest
    UI testing framework code warehouse uitest directory
    https://gitee.com/openharmony/arkXtest
    UI test framework external JS API interface code warehouse
    https://gitee.com/openharmony/interface_sdk-js/blob/master/api/@ohos.uitest.d.ts
    Stability test tool code warehouse
    https://gitee.com/openharmony/wukong
    Compatibility test suite code warehouse
    ACTS: https://gitee.com/openharmony/xts_acts
    DCTS: https://gitee.com/openharmony/xts_dcts
    HATS: https://gitee.com/openharmony/xts_hats


OpenHarmony开发者
160 声望1.1k 粉丝

OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及运营的开源项目,


引用和评论

0 条评论