• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.application.testRunner (TestRunner)
2
3TestRunner模块提供了框架测试的能力。包括准备单元测试环境、运行测试用例。
4
5如果您想实现自己的单元测试框架,您必须继承这个类并覆盖它的所有方法。
6
7> **说明:**
8>
9> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
10
11## 导入模块
12
13```ts
14import TestRunner from '@ohos.application.testRunner';
15```
16
17## TestRunner.onPrepare
18
19onPrepare(): void
20
21为运行测试用例准备单元测试环境
22
23**系统能力:** SystemCapability.Ability.AbilityRuntime.Core
24
25**示例:**
26
27```ts
28export default class UserTestRunner implements TestRunner {
29    onPrepare() {
30        console.log('Trigger onPrepare');
31    }
32    onRun() {}
33};
34```
35
36
37
38## TestRunner.onRun
39
40onRun(): void
41
42运行测试用例
43
44**系统能力:** SystemCapability.Ability.AbilityRuntime.Core
45
46**示例:**
47
48```ts
49export default class UserTestRunner implements TestRunner {
50    onPrepare() {}
51    onRun() {
52        console.log('Trigger onRun');
53    }
54};
55```
56