From ddd68663136952dde106772f1d49234042a68ee4 Mon Sep 17 00:00:00 2001 From: jiyong_sd Date: Sat, 30 Jul 2022 14:22:44 +0800 Subject: [PATCH] Adapt to the new framework Signed-off-by: jiyong_sd Change-Id: I732425347a1a85f34327770937bc79e65fc30a52 --- .../windowStage/dataShareRdbtest/Test.json | 8 +- .../src/main/ets/MainAbility/MainAbility.ts | 2 +- .../ets/{ => MainAbility}/pages/index.ets | 29 +++---- .../src/main/ets/TestAbility/TestAbility.ts | 50 ++++++++++++ .../src/main/ets/TestAbility/pages/index.ets | 48 ++++++++++++ .../ets/TestRunner/OpenHarmonyTestRunner.ts | 78 +++++++++++++++++++ .../DataShareCombinationRdb.ets | 2 +- .../{Test => test}/DataSharePredicatesRdb.ets | 2 +- .../DataSharePublicfunction_Callback.ets | 2 +- .../DataSharePublicfunction_Promise.ets | 2 +- .../DataShareSingleRdb_Callback.ets | 2 +- .../DataShareSingleRdb_Promise.ets | 2 +- .../src/main/ets/{Test => test}/List.test.ets | 0 .../resources/base/profile/main_pages.json | 2 +- 14 files changed, 199 insertions(+), 30 deletions(-) rename distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/{ => MainAbility}/pages/index.ets (62%) create mode 100644 distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/TestAbility.ts create mode 100644 distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/pages/index.ets create mode 100644 distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts rename distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/{Test => test}/DataShareCombinationRdb.ets (97%) rename distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/{Test => test}/DataSharePredicatesRdb.ets (97%) rename distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/{Test => test}/DataSharePublicfunction_Callback.ets (95%) rename distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/{Test => test}/DataSharePublicfunction_Promise.ets (95%) rename distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/{Test => test}/DataShareSingleRdb_Callback.ets (97%) rename distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/{Test => test}/DataShareSingleRdb_Promise.ets (97%) rename distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/{Test => test}/List.test.ets (100%) diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/Test.json b/distributeddatamgr/windowStage/dataShareRdbtest/Test.json index 8244a2b1e..a18d3465d 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/Test.json +++ b/distributeddatamgr/windowStage/dataShareRdbtest/Test.json @@ -1,10 +1,12 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", + "type": "OHJSUnitTest", "test-timeout": "180000", - "package": "com.example.myapplication", - "shell-timeout": "600000" + "bundle-name": "com.example.myapplication", + "module-name": "entry", + "shell-timeout": "600000", + "testcase-timeout": 70000 }, "kits": [{ "test-file-name": [ diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/MainAbility.ts b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/MainAbility.ts index e9cf4fd08..163a930ec 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -125,7 +125,7 @@ export default class MainAbility extends Ability { }); dseConnectionId = await context.connectAbility(dseWant, dseConnect); }) - windowStage.setUIContent(this.context, "pages/index", null) + windowStage.setUIContent(this.context, "MainAbility/pages/index", null) } onWindowStageDestroy() { diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/pages/index.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/pages/index.ets similarity index 62% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/pages/index.ets rename to distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/pages/index.ets index 022c5e3aa..bb3fd411a 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/pages/index.ets +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/pages/index.ets @@ -13,9 +13,10 @@ * limitations under the License. */ import file from '@system.file'; - -import {Core, ExpectExtend} from "hypium/index" -import testsuite from "../Test/List.test" +import router from '@ohos.router'; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../../test/List.test' //InstrumentLog, ReportExtend @@ -25,22 +26,12 @@ struct Index { aboutToAppear(){ console.info("start run testcase!!!!") - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - core.addService('expect', expectExtend) - //const reportExtend = new ReportExtend(file) - - //core.addService('report', reportExtend) - core.init() - //core.subscribeEvent('task', reportExtend) - const configService = core.getDefaultService('config') - console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) - globalThis.abilityWant.parameters.timeout = 70000; - configService.setConfig(globalThis.abilityWant.parameters) - testsuite() - core.execute() + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) } build() { diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/TestAbility.ts b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 000000000..89a847305 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import Ability from '@ohos.application.Ability' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.loadContent("TestAbility/pages/index", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }); + + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +}; \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/pages/index.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 000000000..b93567f96 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@ohos.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..a4ee2f165 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a com.example.myapplication.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareCombinationRdb.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareCombinationRdb.ets similarity index 97% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareCombinationRdb.ets rename to distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareCombinationRdb.ets index f271e7244..292db2853 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareCombinationRdb.ets +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareCombinationRdb.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import dataShare from '@ohos.data.dataShare' import * as pubfun from './DataSharePublicfunction_Promise' import dataSharePredicates from '@ohos.data.dataSharePredicates' diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePredicatesRdb.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePredicatesRdb.ets similarity index 97% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePredicatesRdb.ets rename to distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePredicatesRdb.ets index 9e363a4e1..6b8480121 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePredicatesRdb.ets +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePredicatesRdb.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import dataShare from '@ohos.data.dataShare' import dataSharePredicates from '@ohos.data.dataSharePredicates' import * as pubfun from './DataSharePublicfunction_Promise' diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Callback.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Callback.ets similarity index 95% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Callback.ets rename to distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Callback.ets index d423eac42..1e80d7a50 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Callback.ets +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Callback.ets @@ -14,7 +14,7 @@ */ import file from '@system.file'; -import { describe, it, expect } from 'hypium/index' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import dataShare from '@ohos.data.dataShare' import dataSharePredicates from '@ohos.data.dataSharePredicates' import DataShareResultSet from '@ohos.data.DataShareResultSet' diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Promise.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Promise.ets similarity index 95% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Promise.ets rename to distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Promise.ets index a5f6785c2..5fcd72c06 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Promise.ets +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataSharePublicfunction_Promise.ets @@ -14,7 +14,7 @@ */ import file from '@system.file'; -import { describe, it, expect } from 'hypium/index' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import dataShare from '@ohos.data.dataShare' import dataSharePredicates from '@ohos.data.dataSharePredicates' import DataShareResultSet from '@ohos.data.DataShareResultSet' diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Callback.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Callback.ets similarity index 97% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Callback.ets rename to distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Callback.ets index 2d9f966a4..1a5bd7a8c 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Callback.ets +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Callback.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import dataShare from '@ohos.data.dataShare' import dataSharePredicates from '@ohos.data.dataSharePredicates' import * as pubfun from './DataSharePublicfunction_Callback' diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Promise.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Promise.ets similarity index 97% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Promise.ets rename to distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Promise.ets index 93cbf7510..900f6764a 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Promise.ets +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/DataShareSingleRdb_Promise.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import dataShare from '@ohos.data.dataShare' import dataSharePredicates from '@ohos.data.dataSharePredicates' import * as pubfun from './DataSharePublicfunction_Promise' diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/List.test.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/List.test.ets similarity index 100% rename from distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/List.test.ets rename to distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/test/List.test.ets diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json index feec276e1..c1858c216 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,5 @@ { "src": [ - "pages/index" + "MainAbility/pages/index" ] } -- GitLab