Technology Sharing

Hongmeng language basic class library: [@ohos.application.testRunner (TestRunner)] Test

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

TestRunner

The TestRunner module provides framework testing capabilities, including preparing unit test environments and running test cases.

If you want to implement your own unit testing framework, you must inherit from this class and override all its methods.

illustrate:
Please familiarize yourself with the Hongmeng development guide before developmentgitee.com/li-shizhen-skin/harmony-os/blob/master/README.mdClick or copy to go.
The first batch of interfaces in this module are supported starting from API version 8. For new interfaces in subsequent versions, the starting version of the interface is marked with a superscript.

Importing modules

import TestRunner from '@ohos.application.testRunner'
  • 1

TestRunner.onPrepare

onPrepare(): void

Prepare the unit test environment for running test cases

System capabilities: SystemCapability.Ability.AbilityRuntime.Core

Example:

export default class UserTestRunner implements TestRunner {
    onPrepare() {
        console.log("Trigger onPrepare")
    }
onRun(){}
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

insert image description here

TestRunner.onRun

onRun(): void

Running Test Cases

System capabilities: SystemCapability.Ability.AbilityRuntime.Core

Example:

export default class UserTestRunner implements TestRunner {
    onPrepare() {
       console.log("Trigger onRun")
    }
onRun(){}
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6