1# @ohos.application.testRunner (TestRunner) 2 3The **TestRunner** module provides a test framework. You can use the APIs of this module to prepare the unit test environment and run test cases. 4 5To implement your own unit test framework, extend this class and override its APIs. 6 7> **NOTE** 8> 9> 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. 10> 11> The APIs of this module can be used only in <!--RP1-->[arkxtest](../../application-test/arkxtest-guidelines.md)<!--RP1End-->. 12 13## Modules to Import 14 15```ts 16import { TestRunner } from '@kit.TestKit'; 17``` 18 19## TestRunner.onPrepare 20 21onPrepare(): void 22 23Prepares the unit test environment to run test cases. 24 25**System capability**: SystemCapability.Ability.AbilityRuntime.Core 26 27**Atomic service API**: This API can be used in atomic services since API version 11. 28 29**Example** 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 49Runs test cases. 50 51**System capability**: SystemCapability.Ability.AbilityRuntime.Core 52 53**Atomic service API**: This API can be used in atomic services since API version 11. 54 55**Example** 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