diff --git a/ability/ability_runtime/aacommand/AACommandPrintOneTest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/aacommand/AACommandPrintOneTest/entry/src/main/ets/test/Ability.test.ets index c19ba35c77d451510ef5ea554aa26d6967b3df48..22c198f9aa18824ab770aba482fb02ca43bfb3d0 100644 --- a/ability/ability_runtime/aacommand/AACommandPrintOneTest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/aacommand/AACommandPrintOneTest/entry/src/main/ets/test/Ability.test.ets @@ -27,7 +27,7 @@ export default function abilityTest() { bundleName: "com.example.aacommandprintonetest", abilityName: "MainAbility" } - await globalThis.abilityTestContext.startAbility(wantInfo).then((data) => { + await globalThis.abilityContext.startAbility(wantInfo).then((data) => { console.log("ActsAACommandPrinOneTest startAbility data : " + JSON.stringify(data)); }).catch((err) => { console.log("ActsAACommandPrinOneTest startAbility err : " + JSON.stringify(err)); diff --git a/ability/ability_runtime/aacommand/AACommandPrintSyncTest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/aacommand/AACommandPrintSyncTest/entry/src/main/ets/test/Ability.test.ets index e7fa1a4492b001dc0aae7bcc5baf11fdb3bbf29f..e65d90aeb9b0a225f9493aac580769e14fd8db76 100644 --- a/ability/ability_runtime/aacommand/AACommandPrintSyncTest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/aacommand/AACommandPrintSyncTest/entry/src/main/ets/test/Ability.test.ets @@ -25,7 +25,7 @@ export default function abilityTest() { bundleName: "com.example.aacommandprintsynctest", abilityName: "MainAbility" } - await globalThis.abilityTestContext.startAbility(wantInfo).then((data) => { + await globalThis.abilityContext.startAbility(wantInfo).then((data) => { console.log("ActsAACommandPrintSyncTest startAbility data : " + JSON.stringify(data)); }).catch((err) => { console.log("ActsAACommandPrintSyncTest startAbility err : " + JSON.stringify(err)); diff --git a/ability/ability_runtime/aacommand/AACommandtest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/aacommand/AACommandtest/entry/src/main/ets/MainAbility/MainAbility.ts index 56c4ba65eb101eb99263606b9b2a377cd538db39..7d4790bc0f072477943ae5911ab2ad22bf46f6b5 100644 --- a/ability/ability_runtime/aacommand/AACommandtest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/aacommand/AACommandtest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -32,6 +32,7 @@ async function startAbilityTest(TAG, context) { export default class MainAbility extends Ability { async onCreate(want, launchParam) { + globalThis.abilityContext = this.context; console.log('MainAbility onCreate') let cmd: any let abilityDelegatorArguments: any @@ -315,8 +316,6 @@ export default class MainAbility extends Ability { onWindowStageCreate(windowStage) { console.log('MainAbility onWindowStageCreate') windowStage.setUIContent(this.context, 'pages/index', null) - - globalThis.abilityContext = this.context; } onWindowStageDestroy() { diff --git a/ability/ability_runtime/aacommand/AACommandtest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/aacommand/AACommandtest/entry/src/main/ets/test/Ability.test.ets index b71df96d39d3c6ceff0abeca673347c560be2902..31c9938468c142925deb6dad9d312a1e43a9a107 100644 --- a/ability/ability_runtime/aacommand/AACommandtest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/aacommand/AACommandtest/entry/src/main/ets/test/Ability.test.ets @@ -28,7 +28,7 @@ export default function abilityTest() { bundleName: "com.example.aacommandtest", abilityName: "MainAbility" } - await globalThis.abilityTestContext.startAbility(wantInfo).then((data) => { + await globalThis.abilityContext.startAbility(wantInfo).then((data) => { console.log("ActsAACommandTest startAbility data : " + JSON.stringify(data)); }).catch((err) => { console.log("ActsAACommandTest startAbility err : " + JSON.stringify(err)); diff --git a/ability/ability_runtime/abilitystagemonitor/abilitystagemonitortest/entry/src/main/ets/TestAbility/TestAbility.ts b/ability/ability_runtime/abilitystagemonitor/abilitystagemonitortest/entry/src/main/ets/TestAbility/TestAbility.ts index aed2de2649e977a9671509848a1ed4674cf41c18..d1317f99b914d3bc27274c9ade6bc4a8b62a47fd 100644 --- a/ability/ability_runtime/abilitystagemonitor/abilitystagemonitortest/entry/src/main/ets/TestAbility/TestAbility.ts +++ b/ability/ability_runtime/abilitystagemonitor/abilitystagemonitortest/entry/src/main/ets/TestAbility/TestAbility.ts @@ -19,6 +19,7 @@ import testsuite from '../test/List.test' export default class TestAbility extends Ability { onCreate(want, launchParam) { + globalThis.abilityContext = this.context; console.info('TestAbility onCreate') let abilityDelegatorArguments: any let abilityDelegator: any @@ -34,7 +35,6 @@ export default class TestAbility extends Ability { onWindowStageCreate(windowStage) { console.log('TestAbility onWindowStageCreate') windowStage.setUIContent(this.context, 'TestAbility/pages/index', null) - globalThis.abilityContext = this.context; } onWindowStageDestroy() { diff --git a/ability/ability_runtime/abilitystagemonitor/abilitystagemonitortest/entry/src/main/ets/test/AbilityStageMonitor.test.ets b/ability/ability_runtime/abilitystagemonitor/abilitystagemonitortest/entry/src/main/ets/test/AbilityStageMonitor.test.ets index 5f04d0fe4ca2d5cc38126da543a178d499f21712..8bdca59c2a7c62bfe7a7fcb79402f79f27328341 100644 --- a/ability/ability_runtime/abilitystagemonitor/abilitystagemonitortest/entry/src/main/ets/test/AbilityStageMonitor.test.ets +++ b/ability/ability_runtime/abilitystagemonitor/abilitystagemonitortest/entry/src/main/ets/test/AbilityStageMonitor.test.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { describe, it, expect } from '@ohos/hypium' +import { describe, it, expect, afterEach } from '@ohos/hypium' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); @@ -37,6 +37,24 @@ function test(time) { export default function abilityStageMonitorTest() { describe('ActsAbilityTest', function () { + afterEach(async (done) => { + console.log("SUB_AA_AbilityStageMonitor afterEach called"); + let wantInfo = { + bundleName: "com.example.abilitystagemonitortest", + abilityName: "TestAbility" + } + await globalThis.abilityContext.startAbility(wantInfo).then((data) => { + console.log("SUB_AA_AbilityStageMonitor startAbility data : " + JSON.stringify(data)); + }).catch((err) => { + console.log("SUB_AA_AbilityStageMonitor startAbility err : " + JSON.stringify(err)); + }) + + setTimeout(function () { + console.log("SUB_AA_AbilityStageMonitor afterEach called"); + done(); + }, 1000); + }) + /** * @tc.number: SUB_AA_AbilityStageMonitor_0100 * @tc.name: Call waitAbilityStageMonitor in the form of callback, and enter the monitor diff --git a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets index 7fa7e6243d2d3270b1fc7807f546b64bfcdcba40..cb5e87bb7ce3cc0b319a0a51c8747f5618259ccc 100644 --- a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets @@ -15,6 +15,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import commonEvent from '@ohos.commonEvent' +import backgroundTaskManager from '@ohos.backgroundTaskManager'; let subscriberInfo = { events: ['onCreateMain_To_Test_CommonEvent', @@ -38,22 +39,29 @@ let flagNewWant = false; export default function abilityTest() { describe('ActsNewWantTest', function () { - afterEach(async (done) => { - console.log("ACTS_NewWant afterEach called"); - let wantInfo = { - bundleName: "com.example.newwanttest", - abilityName: "com.example.newwanttest.MainAbility" - } - await globalThis.abilityTestContext.startAbility(wantInfo).then((data) => { - console.log("ACTS_NewWant startAbility data : " + JSON.stringify(data)); - }).catch((err) => { - console.log("ACTS_NewWant startAbility err : " + JSON.stringify(err)); - }) - - setTimeout(function () { - console.log("ACTS_NewWant afterEach end"); - done(); - }, 1000); + let TAG1 = 'ACTS_NewWant_Test : ' + let id = undefined; + beforeAll(async (done) => { + console.log(TAG1 + "beforeAll called"); + let myReason = 'test ActsNewWantTest'; + let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => { + console.log(TAG1 + "Request suspension delay will time out."); + }) + id = delayInfo.requestId; + console.log(TAG1 + "requestId is : " + id); + setTimeout(function () { + console.log(TAG1 + "beforeAll end"); + done(); + }, 1000); + }) + + afterAll(async (done) => { + console.log(TAG1 + "afterAll called"); + backgroundTaskManager.cancelSuspendDelay(id); + setTimeout(function () { + console.log(TAG1 + "afterAll end"); + done(); + }, 1000); }) /**