1# @ohos.application.testRunner (TestRunner)
2
3TestRunner模块提供了框架测试的能力。包括准备单元测试环境、运行测试用例。
4
5如果您想实现自己的单元测试框架,您必须继承这个类并覆盖它的所有方法。
6
7> **说明:**
8>
9> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
10>
11> 本模块接口仅可在<!--RP1-->[自动化测试框架arkxtest](../../application-test/arkxtest-guidelines.md)<!--RP1End-->中使用。
12
13## 导入模块
14
15```ts
16import { TestRunner } from '@kit.TestKit';
17```
18
19## TestRunner.onPrepare
20
21onPrepare(): void
22
23为运行测试用例准备单元测试环境
24
25**系统能力:** SystemCapability.Ability.AbilityRuntime.Core
26
27**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
28
29**示例:**
30
31```ts
32import { TestRunner } from '@kit.TestKit';
33
34export default class UserTestRunner implements TestRunner {
35  onPrepare() {
36    console.log('Trigger onPrepare');
37  }
38  onRun() {
39  }
40};
41```
42
43
44
45## TestRunner.onRun
46
47onRun(): void
48
49运行测试用例
50
51**系统能力:** SystemCapability.Ability.AbilityRuntime.Core
52
53**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
54
55**示例:**
56
57```ts
58import { TestRunner } from '@kit.TestKit';
59
60export default class UserTestRunner implements TestRunner {
61  onPrepare() {
62  }
63  onRun() {
64    console.log('Trigger onRun');
65  }
66};
67```
68