本文讲述如何在ACTS/DCTS新增用例应用。
环境:OpenHarmony5.0Release

新建工程

在DevEco Studio中新建一个Stage模型的应用,工程copy 至acts/dcts 的对应目录下。

配置hvigor

当前OpenHarmony5.0Release 镜像源码编译的hvigor插件选择4.0.5 版本,高于该版本会编译失败。修改工程目录 hvigor/hvigor-config.json5 中的hvigorVersion 为4.0.5。

{
   "hvigorVersion": "4.0.5",
  "dependencies": {
    "@ohos/hvigor-ohos-plugin": "4.0.5"
  },
......
}

如果版本不对,同步修改hvigor/hvigor-wrapper.js中的内容,可以在镜像源码中选择一个hvigor-ohos-plugin": "4.0.5"对应过程的hvigor-wrapper.js复制过来。

配置BUILD.gn

import("//test/xts/tools/build/suite.gni")
ohos_js_app_suite("XXXTest") {
  testonly = true
  certificate_profile = "./signature/openharmony_sx.p7b"
  hap_name = "XXXTest"
  subsystem_name = "communication"
  part_name = "dsoftbus"
}

配置signature

使用OpenHarmony签名工具新建一个套签名文件,将p7b 文件名修改为openharmony_sx.p7b,同时复制到signature目录下,改文件位置和文件名参考BUILD.gn中certificate_profile 配置。

增加编译项

已在dcts/communication 中新增加为例:
修改 test/xts/dcts/communication 目录下的BUILD.gn 文件。

import("//build/ohos_var.gni")
group("communication") {
  testonly = true
  if (is_standard_system) {
    deps = [
      "dsoftbus/rpc:DctsRpcJsTest",
      ......
      "softbus_standard/transmission/sessionmgt:DctsSoftBusTransSessionFunTest",
      "xxxx/xxxx:XXXTest", // 新增加用例
    ]
  } else {
    deps = [ "wifi_standard:ActsWifiJSTest" ]
  }
}

配置Test.json

在新建项目的根目录新增如Test.json

{
    "description": "Configuration for rpc Tests",
    "driver": {
        "type": "OHJSUnitTest",
        "test-timeout": "900000",
        "shell-timeout": "900000",
        "testcase-timeout": "60000",
        "package-name": "com.ohos.xxx",
        "bundle-name": "com.ohos.xxx"

    },
    "kits": [
        {
            "test-file-name": [
                "XXXTest.hap"
            ],
            "type": "AppInstallKit",
            "cleanup-apps": true
        }
    ]
}

配置用例

在目录下新建test 文件目录,新建List.test.ets 和XXXTest.ets 文件。
List.test.ets:

import XXXTestfrom './XXXTest'
export default function List() {
  XXXTest()
}

XXXTest.ets:

import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"
import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import { UiDriver, BY } from '@ohos.UiTest';
let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator();

export default function XXXTest() {
  describe('XXXTest', function () {
    function sleep(ms) {
          return new Promise(resolve => setTimeout(resolve, ms));
    }
    beforeAll(async function (done) {
      console.log('DMS before began')
      await sleep(1000);
      done()
    });
    beforeEach(async function (done) {
      console.info('LifeCycleTest before each called');
      await sleep(1000);
      done()
    });
    afterEach(async function (done) {
      console.info('LifeCycleTest after each called');
      await sleep(1000);
      done();
    });
    it("XXXTest_CASE01", 0, async function (done) {
      console.info("---------------XXXTest_CASE01 is start---------------")
      expect(100 == 100).assertTrue();
      done();
  })
}

编译

在工程的 /test/xts/acts目录下执行下面命令生成dcts 测试套。

./build.sh product_name=rk3568 system_size=standard
Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐