js-apis-testRunner.md 1.1 KB
Newer Older
W
wusongqing 已提交
1 2
# TestRunner

3 4 5 6
The **TestRunner** module provides a test framework. You can use the APIs of this module to prepare the unit test environment and run test cases.

To implement your own unit test framework, extend this class and override its APIs.

W
wusongqing 已提交
7 8 9
> **NOTE**
> 
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 
W
wusongqing 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

## Modules to Import

```js
import TestRunner from '@ohos.application.testRunner'
```

## TestRunner.onPrepare

onPrepare(): void

Prepares the unit test environment to run test cases.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Example**

```js
28
export default class UserTestRunner implements TestRunner {
W
wusongqing 已提交
29 30 31
    onPrepare() {
        console.log("Trigger onPrepare")
    }
G
Gloria 已提交
32
    onRun() {}
W
wusongqing 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
};
```



## TestRunner.onRun

onRun(): void

Runs test cases.

**System capability**: SystemCapability.Ability.AbilityRuntime.Core

**Example**

```js
49
export default class UserTestRunner implements TestRunner {
G
Gloria 已提交
50 51 52
    onPrepare() {}
    onRun() {
        console.log("Trigger onRun")
W
wusongqing 已提交
53 54 55
    }
};
```