# AMSFADemo **Repository Path**: jiangwensai/amsfademo ## Basic Information - **Project Name**: AMSFADemo - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2022-04-26 - **Last Updated**: 2022-04-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AMSFADemo #### 简介 本示例展示了OpenHarmony FA模型下Api的自动化测试用例。 #### 使用说明 一键式双击**auto_fa.bat**脚本(安装自动化测试用例hap及运行) #### 创建测试用例 DevEco Studio在ohosTest目录下自动生成对应测试类(**Ability.test.ets**) 开发者需要在测试类中根据业务逻辑进行开发。 #### 编写测试用例 在Ability.test.ets文件中,导入所需模块; **describe**代表一个测试套:第一个参数代表测试套名称;第二个参数代表测试套函数。 **it**代表一条测试用例:第一个参数代表用例名称;第二个参数代表过滤参数;第三个参数代表用例函数。 **expect(断言)**用于验证测试用例运行结果正确与否。 测试套函数需传入参数**done**,每条测试用例执行完毕后调用**done()**来结束。 示例代码: ``` import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' import featureAbility from '@ohos.ability.featureAbility'; export default function appTest() { describe('AutomationFATest', function (done) { it('startPageAbilityTestcase', 0, async function (done) { console.log(printLog + 'startPageAbilityTestcase ====< begin'); let parameter = { "want": { bundleName: "com.example.amsfaapplication", abilityName: "com.example.amsfaapplication.SecondAbility" } } await featureAbility.startAbility(parameter, (err, data) => { console.log(printLog + "start page ability" + JSON.stringify(err) + ", " + JSON.stringify(data)); expect(0).assertEqual(err.code) done(); }) }) }) } ``` #### 运行测试用例 除命令行运行用例外,还有两种方式执行测试用例。 1.在执行ohosTest用例前,首先构建带签名信息的hap包。 在工程目录**右键>Run‘测试类名称’** 2.在Ability.test.ets文件中,点击对应方法左侧绿色运行按钮。 **判断测试用例是否通过**需要在日志中筛选JsApp,**total cases**代表用例通过与失败的结果。