已合并
切换编译ut——testbundle——previewTest #4449
AtomGit-Bot创建于 2023年7月25日
切换编译ut——testbundle——previewTest #4449
已合并
AtomGit-Bot创建于 2023年7月25日
从refs/pull/4449/head合入到master
共 39 个文件变更+728-371
@@ -0,0 +1,11 @@
1+/node_modules
2+/oh_modules
3+/local.properties
4+/.idea
5+**/build
6+/.hvigor
7+.cxx
8+/.clangd
9+/.clang-format
10+/.clang-tidy
11+**/.test
@@ -1,16 +0,0 @@
1-{
2- "app": {
3- "apiReleaseType": "Beta1",
4- "bundleName": "com.example.previewtest",
5- "debug": true,
6- "icon": "$media:app_icon",
7- "iconId": 16777217,
8- "label": "$string:app_name",
9- "labelId": 16777216,
10- "minAPIVersion": 9,
11- "targetAPIVersion": 9,
12- "vendor": "example",
13- "versionCode": 1000000,
14- "versionName": "1.0.0"
15- }
16-}
@@ -0,0 +1,25 @@
1+/**
2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+{
17+ "app": {
18+ "bundleName": "com.example.previewtest",
19+ "vendor": "example",
20+ "versionCode": 1000000,
21+ "versionName": "1.0.0",
22+ "icon": "$media:app_icon",
23+ "label": "$string:app_name"
24+ }
25+}
@@ -1,8 +1,8 @@
1{1{
2- "string":[2+ "string": [
3 {3 {
4- "name":"app_name",4+ "name": "app_name",
5- "value":"ohosProject"5+ "value": "previewTest"
6 }6 }
7 ]7 ]
8-} 8+}
Rtest/sceneProject/unittest/test_bundle/previewTest/entry/src/main/resources/base/media/app_icon.png→test/sceneProject/unittest/test_bundle/previewTest/AppScope/resources/base/media/app_icon.png+0-0
@@ -1,4 +1,4 @@
1-# Copyright (c) 2022 Huawei Device Co., Ltd.1+# Copyright (c) 2023 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at4# You may obtain a copy of the License at
@@ -12,32 +12,13 @@
12# limitations under the License.12# limitations under the License.
13 13 
14import("//build/ohos.gni")14import("//build/ohos.gni")
15-import("../../../../../appexecfwk.gni")
16 15 
17-ohos_hap("previewTest") {16+ohos_app("previewTest") {
18- hap_profile = "entry/src/main/module.json"
19 hap_name = "preview"17 hap_name = "preview"
20 subsystem_name = "bundlemanager"18 subsystem_name = "bundlemanager"
21- final_hap_path = "$root_out_dir/tests/unittest/bundle_framework/bundlemgrservice/resource/test_bundle/${hap_name}.hap"19+ part_name = "bundle_framework"
20+ certificate_profile =
21+ "./signature/auto_ohos_default_previewTest_com.example.previewtest.p7b"
22 testonly = true22 testonly = true
23- deps = [23+ hap_out_dir = "$root_out_dir/tests/unittest/bundle_framework/bundlemgrservice/resource/test_bundle"
24- ":hjs_demo_js_assets",
25- ":hjs_demo_resources",
26- ]
27- certificate_profile = "${bundle_framework_path}/test/sceneProject/signature/com.example.previewtest.p7b"
28-}
29- 
30-ohos_app_scope("bmsstagedemoone_app_profile") {
31- app_profile = "AppScope/app.json"
32- sources = [ "AppScope/resources" ]
33-}
34- 
35-ohos_js_assets("hjs_demo_js_assets") {
36- source_dir = "entry/src/main/ets"
37-}
38- 
39-ohos_resources("hjs_demo_resources") {
40- sources = [ "entry/src/main/resources" ]
41- deps = [ ":bmsstagedemoone_app_profile" ]
42- hap_profile = "entry/src/main/module.json"
43}24}
Rtest/sceneProject/unittest/test_bundle/previewTest/entry/src/main/ets/MainAbility/MainAbility.ts→test/sceneProject/unittest/test_bundle/previewTest/build-profile.json5+28-37
@@ -1,5 +1,5 @@
1-/*1+/**
2- * Copyright (c) 2022 Huawei Device Co., Ltd.2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -13,39 +13,30 @@
13 * limitations under the License.13 * limitations under the License.
14 */14 */
15 15 
16-import Ability from '@ohos.app.ability.UIAbility'16+{
17- 17+ "app": {
18-export default class MainAbility extends Ability {18+ "signingConfigs": [],
19- onCreate(want,launchParam){19+ "compileSdkVersion": 10,
20- // Ability is creating, initialize resources for this ability20+ "compatibleSdkVersion": 9,
21- console.log("[Demo] MainAbility onCreate")21+ "products": [
22- globalThis.abilityWant = want;22+ {
23+ "name": "default",
24+ "signingConfig": "default"
25+ }
26+ ]
27+ },
28+ "modules": [
29+ {
30+ "name": "entry",
31+ "srcPath": "./entry",
32+ "targets": [
33+ {
34+ "name": "default",
35+ "applyToProducts": [
36+ "default"
37+ ]
38+ }
39+ ]
23 }40 }
24- 41+ ]
25- onDestroy() {42+}
26- // Ability is destroying, release resources for this ability
27- console.log("[Demo] MainAbility onDestroy")
28- }
29- 
30- onWindowStageCreate(windowStage) {
31- // Main window is created, set main page for this ability
32- console.log("[Demo] MainAbility onWindowStageCreate")
33- globalThis.abilityContext = this.context
34- windowStage.setUIContent(this.context, "pages/index/index", null)
35- }
36- 
37- onWindowStageDestroy() {
38- //Main window is destroyed, release UI related resources
39- console.log("[Demo] MainAbility onWindowStageDestroy")
40- }
41- 
42- onForeground() {
43- // Ability has brought to foreground
44- console.log("[Demo] MainAbility onForeground")
45- }
46- 
47- onBackground() {
48- // Ability has back to background
49- console.log("[Demo] MainAbility onBackground")
50- }
51-};
@@ -0,0 +1,6 @@
1+/node_modules
2+/oh_modules
3+/.preview
4+/build
5+/.cxx
6+/.test
Rtest/sceneProject/unittest/test_bundle/previewTest/entry/src/main/ets/FormAbility/FormAbility.ts→test/sceneProject/unittest/test_bundle/previewTest/entry/build-profile.json5+14-38
@@ -1,5 +1,5 @@
1-/*1+/**
2- * Copyright (c) 2022 Huawei Device Co., Ltd.2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -13,40 +13,16 @@
13 * limitations under the License.13 * limitations under the License.
14 */14 */
15 15 
16-import FormExtension from '@ohos.app.form.FormExtensionAbility';16+{
17-import formBindingData from '@ohos.application.formBindingData';17+ "apiType": 'stageMode',
18-import formInfo from '@ohos.application.formInfo';18+ "buildOption": {
19- 19+ },
20-export default class FormAbility extends FormExtension {20+ "targets": [
21- onAddForm(want) {21+ {
22- // Called to return a FormBindingData object.22+ "name": "default",
23- let formData = {};23+ },
24- return formBindingData.createFormBindingData(formData);24+ {
25+ "name": "ohosTest",
25 }26 }
26- 27+ ]
27- onCastToNormalForm(formId) {28+}
28- // Called when the form provider is notified that a temporary form is successfully
29- // converted to a normal form.
30- }
31- 
32- onUpdateForm(formId) {
33- // Called to notify the form provider to update a specified form.
34- }
35- 
36- onChangeFormVisibility(newStatus) {
37- // Called when the form provider receives form events from the system.
38- }
39- 
40- onFormEvent(formId, message) {
41- // Called when a specified message event defined by the form provider is triggered.
42- }
43- 
44- onRemoveForm(formId) {
45- // Called to notify the form provider that a specified form has been destroyed.
46- }
47- 
48- onAcquireFormState(want) {
49- // Called to return a {@link FormState} object.
50- return formInfo.FormState.READY;
51- }
52-};
@@ -0,0 +1,2 @@
1+// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
2+export { hapTasks } from '@ohos/hvigor-ohos-plugin';
@@ -0,0 +1,25 @@
1+/**
2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+{
17+ "license": "",
18+ "devDependencies": {},
19+ "author": "",
20+ "name": "entry",
21+ "description": "Please describe the basic information.",
22+ "main": "",
23+ "version": "1.0.0",
24+ "dependencies": {}
25+}
@@ -1,52 +0,0 @@
1-/*
2- * Copyright (c) 2022 Huawei Device Co., Ltd.
3- * Licensed under the Apache License, Version 2.0 (the "License");
4- * you may not use this file except in compliance with the License.
5- * You may obtain a copy of the License at
6- *
7- * http://www.apache.org/licenses/LICENSE-2.0
8- *
9- * Unless required by applicable law or agreed to in writing, software
10- * distributed under the License is distributed on an "AS IS" BASIS,
11- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12- * See the License for the specific language governing permissions and
13- * limitations under the License.
14- */
15- 
16-import FormExtension from '@ohos.app.form.FormExtensionAbility';
17-import formBindingData from '@ohos.application.formBindingData';
18-import formInfo from '@ohos.application.formInfo';
19- 
20-export default class FormAbility extends FormExtension {
21- onAddForm(want) {
22- // Called to return a FormBindingData object.
23- let formData = {};
24- return formBindingData.createFormBindingData(formData);
25- }
26- 
27- onCastToNormalForm(formId) {
28- // Called when the form provider is notified that a temporary form is successfully
29- // converted to a normal form.
30- }
31- 
32- onUpdateForm(formId) {
33- // Called to notify the form provider to update a specified form.
34- }
35- 
36- onChangeFormVisibility(newStatus) {
37- // Called when the form provider receives form events from the system.
38- }
39- 
40- onFormEvent(formId, message) {
41- // Called when a specified message event defined by the form provider is triggered.
42- }
43- 
44- onRemoveForm(formId) {
45- // Called to notify the form provider that a specified form has been destroyed.
46- }
47- 
48- onAcquireFormState(want) {
49- // Called to return a {@link FormState} object.
50- return formInfo.FormState.READY;
51- }
52-};
@@ -0,0 +1,41 @@
1+import UIAbility from '@ohos.app.ability.UIAbility';
2+import hilog from '@ohos.hilog';
3+import window from '@ohos.window';
4+ 
5+export default class EntryAbility extends UIAbility {
6+ onCreate(want, launchParam) {
7+ hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
8+ }
9+ 
10+ onDestroy() {
11+ hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
12+ }
13+ 
14+ onWindowStageCreate(windowStage: window.WindowStage) {
15+ // Main window is created, set main page for this ability
16+ hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
17+ 
18+ windowStage.loadContent('pages/Index', (err, data) => {
19+ if (err.code) {
20+ hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
21+ return;
22+ }
23+ hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
24+ });
25+ }
26+ 
27+ onWindowStageDestroy() {
28+ // Main window is destroyed, release UI related resources
29+ hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
30+ }
31+ 
32+ onForeground() {
33+ // Ability has brought to foreground
34+ hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
35+ }
36+ 
37+ onBackground() {
38+ // Ability has back to background
39+ hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
40+ }
41+}
Rtest/sceneProject/unittest/test_bundle/previewTest/entry/src/main/ets/Application/AbilityStage.ts→test/sceneProject/unittest/test_bundle/previewTest/entry/src/main/ets/pages/Index.ets+17-9
@@ -1,5 +1,5 @@
1-/*1+/**
2- * Copyright (c) 2022 Huawei Device Co., Ltd.2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -13,12 +13,20 @@
13 * limitations under the License.13 * limitations under the License.
14 */14 */
15 15 
16-import AbilityStage from "@ohos.app.ability.AbilityStage"16+@Entry
17+@Component
18+struct Index {
19+ @State message: string = 'Hello World'
17 20 
18-export default class MyAbilityStage extends AbilityStage {21+ build() {
19- onCreate() {22+ Row() {
20- console.log("[Demo] MyAbilityStage onCreate")23+ Column() {
21- globalThis.stageOnCreateRun = 1;24+ Text(this.message)
22- globalThis.stageContext = this.context;25+ .fontSize(50)
26+ .fontWeight(FontWeight.Bold)
27+ }
28+ .width('100%')
23 }29 }
24-}30+ .height('100%')
31+ }
32+}
@@ -1,66 +0,0 @@
1-/*
2- * Copyright (c) 2022 Huawei Device Co., Ltd.
3- * Licensed under the Apache License, Version 2.0 (the "License");
4- * you may not use this file except in compliance with the License.
5- * You may obtain a copy of the License at
6- *
7- * http://www.apache.org/licenses/LICENSE-2.0
8- *
9- * Unless required by applicable law or agreed to in writing, software
10- * distributed under the License is distributed on an "AS IS" BASIS,
11- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12- * See the License for the specific language governing permissions and
13- * limitations under the License.
14- */
15-import file from '@system.file';
16- 
17-import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets"
18-import testsuite from "../../test/List.test.ets"
19- 
20- 
21-@Entry
22-@Component
23-struct Index {
24- 
25- aboutToAppear(){
26- console.info("start run testcase!!!!")
27- const core = Core.getInstance()
28- const expectExtend = new ExpectExtend({
29- 'id': 'extend'
30- })
31- core.addService('expect', expectExtend)
32- const reportExtend = new ReportExtend(file)
33- 
34- core.addService('report', reportExtend)
35- core.init()
36- core.subscribeEvent('task', reportExtend)
37- const configService = core.getDefaultService('config')
38- console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
39- globalThis.abilityWant.parameters.timeout = 70000;
40- configService.setConfig(globalThis.abilityWant.parameters)
41- testsuite(globalThis.abilityContext)
42- core.execute()
43- }
44- 
45- build() {
46- Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
47- Text('Hello World')
48- .fontSize(50)
49- .fontWeight(FontWeight.Bold)
50- Button() {
51- Text('next page')
52- .fontSize(25)
53- .fontWeight(FontWeight.Bold)
54- }.type(ButtonType.Capsule)
55- .margin({
56- top: 20
57- })
58- .backgroundColor('#0D9FFB')
59- .onClick(() => {
60- 
61- })
62- }
63- .width('100%')
64- .height('100%')
65- }
66-}
@@ -1,63 +0,0 @@
1-{
2- "module": {
3- "abilities": [
4- {
5- "description": "$string:MainAbility_desc",
6- "descriptionId": 16777218,
7- "icon": "$media:icon",
8- "iconId": 16777222,
9- "label": "$string:MainAbility_label",
10- "labelId": 16777219,
11- "name": "MainAbility",
12- "skills": [
13- {
14- "actions": [
15- "action.system.home"
16- ],
17- "entities": [
18- "entity.system.home"
19- ]
20- }
21- ],
22- "srcEntry": "./ets/MainAbility/MainAbility.ts",
23- "startWindowBackground": "$color:white",
24- "startWindowBackgroundId": 16777221,
25- "startWindowIcon": "$media:icon",
26- "startWindowIconId": 16777222,
27- "exported": true
28- }
29- ],
30- "deliveryWithInstall": true,
31- "description": "$string:entry_desc",
32- "descriptionId": 16777220,
33- "deviceTypes": [
34- "2in1",
35- "default",
36- "tablet"
37- ],
38- "extensionAbilities": [
39- {
40- "name": "extensionAbility_A",
41- "skills": [
42- {
43- "actions": [
44- "action.system.home"
45- ],
46- "entities": [
47- "entity.system.home"
48- ]
49- }
50- ],
51- "srcEntry": "",
52- "type": "preview"
53- }
54- ],
55- "installationFree": false,
56- "mainElement": "MainAbility",
57- "name": "entry",
58- "pages": "$profile:main_pages",
59- "srcEntry": "./ets/Application/AbilityStage.ts",
60- "type": "entry",
61- "virtualMachine": "ark"
62- }
63-}
@@ -0,0 +1,69 @@
1+/**
2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+{
17+ "module": {
18+ "abilities": [
19+ {
20+ "name": "EntryAbility",
21+ "srcEntry": "./ets/entryability/EntryAbility.ts",
22+ "description": "$string:EntryAbility_desc",
23+ "icon": "$media:icon",
24+ "label": "$string:EntryAbility_label",
25+ "startWindowIcon": "$media:icon",
26+ "startWindowBackground": "$color:start_window_background",
27+ "exported": true,
28+ "skills": [
29+ {
30+ "entities": [
31+ "entity.system.home"
32+ ],
33+ "actions": [
34+ "action.system.home"
35+ ]
36+ }
37+ ]
38+ }
39+ ],
40+ "deliveryWithInstall": true,
41+ "deviceTypes": [
42+ "default",
43+ "tablet"
44+ ],
45+ "extensionAbilities": [
46+ {
47+ "name": "extensionAbility_A",
48+ "skills": [
49+ {
50+ "actions": [
51+ "action.system.home"
52+ ],
53+ "entities": [
54+ "entity.system.home"
55+ ]
56+ }
57+ ],
58+ "srcEntry": "",
59+ "type": "preview"
60+ }
61+ ],
62+ "installationFree": false,
63+ "mainElement": "MainAbility",
64+ "name": "entry",
65+ "pages": "$profile:main_pages",
66+ "type": "entry",
67+ "virtualMachine": "ark"
68+ }
69+}
@@ -1,8 +1,8 @@
1{1{
2- "color": [2+ "color": [
3- {3+ {
4- "name": "white",4+ "name": "start_window_background",
5- "value": "#16777221"5+ "value": "#FFFFFF"
6- }6+ }
7- ]7+ ]
8-}8+}
@@ -1,20 +1,16 @@
1{1{
2- "string": [2+ "string": [
3- {3+ {
4- "name": "MainAbility_desc",4+ "name": "module_desc",
5- "value": "description"5+ "value": "module description"
6- },6+ },
7- {7+ {
8- "name": "MainAbility_label",8+ "name": "EntryAbility_desc",
9- "value": "label"9+ "value": "description"
10- },10+ },
11- {11+ {
12- "name": "entry_desc",12+ "name": "EntryAbility_label",
13- "value": "description"13+ "value": "label"
14- },14+ }
15- {15+ ]
16- "name": "app_name",16+}
17- "value": "label"
18- }
19- ]
20-}
@@ -1,6 +1,5 @@
1{1{
2- "src": [2+ "src": [
3- "pages/index/index",3+ "pages/Index"
4- "pages/second/second"4+ ]
5- ]5+}
6-}
@@ -0,0 +1,16 @@
1+{
2+ "string": [
3+ {
4+ "name": "module_desc",
5+ "value": "module description"
6+ },
7+ {
8+ "name": "EntryAbility_desc",
9+ "value": "description"
10+ },
11+ {
12+ "name": "EntryAbility_label",
13+ "value": "label"
14+ }
15+ ]
16+}
@@ -0,0 +1,16 @@
1+{
2+ "string": [
3+ {
4+ "name": "module_desc",
5+ "value": "模块描述"
6+ },
7+ {
8+ "name": "EntryAbility_desc",
9+ "value": "description"
10+ },
11+ {
12+ "name": "EntryAbility_label",
13+ "value": "label"
14+ }
15+ ]
16+}
@@ -0,0 +1,50 @@
1+/**
2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+import hilog from '@ohos.hilog';
17+import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
18+ 
19+export default function abilityTest() {
20+ describe('ActsAbilityTest', function () {
21+ // Defines a test suite. Two parameters are supported: test suite name and test suite function.
22+ beforeAll(function () {
23+ // Presets an action, which is performed only once before all test cases of the test suite start.
24+ // This API supports only one parameter: preset action function.
25+ })
26+ beforeEach(function () {
27+ // Presets an action, which is performed before each unit test case starts.
28+ // The number of execution times is the same as the number of test cases defined by **it**.
29+ // This API supports only one parameter: preset action function.
30+ })
31+ afterEach(function () {
32+ // Presets a clear action, which is performed after each unit test case ends.
33+ // The number of execution times is the same as the number of test cases defined by **it**.
34+ // This API supports only one parameter: clear action function.
35+ })
36+ afterAll(function () {
37+ // Presets a clear action, which is performed after all test cases of the test suite end.
38+ // This API supports only one parameter: clear action function.
39+ })
40+ it('assertContain',0, function () {
41+ // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
42+ hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
43+ let a = 'abc'
44+ let b = 'b'
45+ // Defines a variety of assertion methods, which are used to declare expected boolean conditions.
46+ expect(a).assertContain(b)
47+ expect(a).assertEqual(a)
48+ })
49+ })
50+}
Rtest/sceneProject/unittest/test_bundle/previewTest/entry/src/main/ets/test/List.test.ets→test/sceneProject/unittest/test_bundle/previewTest/entry/src/ohosTest/ets/test/List.test.ets+5-3
@@ -1,5 +1,5 @@
1-/*1+/**
2- * Copyright (c) 2022 Huawei Device Co., Ltd.2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -13,6 +13,8 @@
13 * limitations under the License.13 * limitations under the License.
14 */14 */
15 15 
16+import abilityTest from './ability.test'
16 17 
17-export default function testsuite(context) {18+export default function testsuite() {
19+ abilityTest()
18}20}
@@ -0,0 +1,63 @@
1+/**
2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+import UIAbility from '@ohos.app.ability.UIAbility';
17+import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
18+import hilog from '@ohos.hilog';
19+import { Hypium } from '@ohos/hypium';
20+import testsuite from '../test/List.test';
21+import window from '@ohos.window';
22+ 
23+export default class TestAbility extends UIAbility {
24+ onCreate(want, launchParam) {
25+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
26+ hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
27+ hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
28+ var abilityDelegator: any
29+ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
30+ var abilityDelegatorArguments: any
31+ abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
32+ hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
33+ Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
34+ }
35+ 
36+ onDestroy() {
37+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
38+ }
39+ 
40+ onWindowStageCreate(windowStage: window.WindowStage) {
41+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
42+ windowStage.loadContent('testability/pages/Index', (err, data) => {
43+ if (err.code) {
44+ hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
45+ return;
46+ }
47+ hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
48+ JSON.stringify(data) ?? '');
49+ });
50+ }
51+ 
52+ onWindowStageDestroy() {
53+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
54+ }
55+ 
56+ onForeground() {
57+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
58+ }
59+ 
60+ onBackground() {
61+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
62+ }
63+}
@@ -0,0 +1,49 @@
1+/**
2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+import hilog from '@ohos.hilog';
17+ 
18+@Entry
19+@Component
20+struct Index {
21+ aboutToAppear() {
22+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
23+ }
24+ @State message: string = 'Hello World'
25+ build() {
26+ Row() {
27+ Column() {
28+ Text(this.message)
29+ .fontSize(50)
30+ .fontWeight(FontWeight.Bold)
31+ Button() {
32+ Text('next page')
33+ .fontSize(20)
34+ .fontWeight(FontWeight.Bold)
35+ }.type(ButtonType.Capsule)
36+ .margin({
37+ top: 20
38+ })
39+ .backgroundColor('#0D9FFB')
40+ .width('35%')
41+ .height('5%')
42+ .onClick(()=>{
43+ })
44+ }
45+ .width('100%')
46+ }
47+ .height('100%')
48+ }
49+ }
@@ -0,0 +1,49 @@
1+import hilog from '@ohos.hilog';
2+import TestRunner from '@ohos.application.testRunner';
3+import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
4+ 
5+var abilityDelegator = undefined
6+var abilityDelegatorArguments = undefined
7+ 
8+async function onAbilityCreateCallback() {
9+ hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
10+}
11+ 
12+async function addAbilityMonitorCallback(err: any) {
13+ hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
14+}
15+ 
16+export default class OpenHarmonyTestRunner implements TestRunner {
17+ constructor() {
18+ }
19+ 
20+ onPrepare() {
21+ hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
22+ }
23+ 
24+ async onRun() {
25+ hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
26+ abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
27+ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
28+ var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
29+ let lMonitor = {
30+ abilityName: testAbilityName,
31+ onAbilityCreate: onAbilityCreateCallback,
32+ };
33+ abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
34+ var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
35+ var debug = abilityDelegatorArguments.parameters['-D']
36+ if (debug == 'true')
37+ {
38+ cmd += ' -D'
39+ }
40+ hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
41+ abilityDelegator.executeShellCommand(cmd,
42+ (err: any, d: any) => {
43+ hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
44+ hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
45+ hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
46+ })
47+ hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
48+ }
49+}
@@ -0,0 +1,51 @@
1+/**
2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+{
17+ "module": {
18+ "name": "entry_test",
19+ "type": "feature",
20+ "description": "$string:module_test_desc",
21+ "mainElement": "TestAbility",
22+ "deviceTypes": [
23+ "default"
24+ ],
25+ "deliveryWithInstall": true,
26+ "installationFree": false,
27+ "pages": "$profile:test_pages",
28+ "abilities": [
29+ {
30+ "name": "TestAbility",
31+ "srcEntry": "./ets/testability/TestAbility.ets",
32+ "description": "$string:TestAbility_desc",
33+ "icon": "$media:icon",
34+ "label": "$string:TestAbility_label",
35+ "exported": true,
36+ "startWindowIcon": "$media:icon",
37+ "startWindowBackground": "$color:start_window_background",
38+ "skills": [
39+ {
40+ "actions": [
41+ "action.system.home"
42+ ],
43+ "entities": [
44+ "entity.system.home"
45+ ]
46+ }
47+ ]
48+ }
49+ ]
50+ }
51+}
@@ -0,0 +1,8 @@
1+{
2+ "color": [
3+ {
4+ "name": "start_window_background",
5+ "value": "#FFFFFF"
6+ }
7+ ]
8+}
@@ -0,0 +1,16 @@
1+{
2+ "string": [
3+ {
4+ "name": "module_test_desc",
5+ "value": "test ability description"
6+ },
7+ {
8+ "name": "TestAbility_desc",
9+ "value": "the test ability"
10+ },
11+ {
12+ "name": "TestAbility_label",
13+ "value": "test label"
14+ }
15+ ]
16+}
Rtest/sceneProject/unittest/test_bundle/previewTest/entry/src/main/resources/base/media/aa_icon.png→test/sceneProject/unittest/test_bundle/previewTest/entry/src/ohosTest/resources/base/media/icon.png+0-0
@@ -0,0 +1,5 @@
1+{
2+ "src": [
3+ "testability/pages/Index"
4+ ]
5+}
@@ -0,0 +1,21 @@
1+/**
2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+{
17+ "hvigorVersion": "2.4.2",
18+ "dependencies": {
19+ "@ohos/hvigor-ohos-plugin": "2.4.2"
20+ }
21+}
@@ -0,0 +1,2 @@
1+// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
2+export { appTasks } from '@ohos/hvigor-ohos-plugin';
@@ -0,0 +1,61 @@
1+# Copyright (c) 2023 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+#!/bin/bash
15+ 
16+# ----------------------------------------------------------------------------
17+# Hvigor startup script, version 1.0.0
18+#
19+# Required ENV vars:
20+# ------------------
21+# NODE_HOME - location of a Node home dir
22+# or
23+# Add /usr/local/nodejs/bin to the PATH environment variable
24+# ----------------------------------------------------------------------------
25+ 
26+HVIGOR_APP_HOME=$(dirname $(readlink -f $0))
27+HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
28+warn() {
29+ echo ""
30+ echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
31+}
32+ 
33+error() {
34+ echo ""
35+ echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
36+}
37+ 
38+fail() {
39+ error "$@"
40+ exit 1
41+}
42+ 
43+# Determine node to start hvigor wrapper script
44+if [ -n "${NODE_HOME}" ];then
45+ EXECUTABLE_NODE="${NODE_HOME}/bin/node"
46+ if [ ! -x "$EXECUTABLE_NODE" ];then
47+ fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed"
48+ fi
49+else
50+ EXECUTABLE_NODE="node"
51+ which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
52+fi
53+ 
54+# Check hvigor wrapper script
55+if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
56+ fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
57+fi
58+ 
59+# start hvigor-wrapper script
60+exec "${EXECUTABLE_NODE}" \
61+ "${HVIGOR_WRAPPER_SCRIPT}" "$@"
Rtest/sceneProject/unittest/test_bundle/previewTest/entry/src/main/ets/pages/second/second.ets→test/sceneProject/unittest/test_bundle/previewTest/oh-package-lock.json5+13-27
@@ -1,5 +1,5 @@
1-/*1+/**
2- * Copyright (c) 2022 Huawei Device Co., Ltd.2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at5 * You may obtain a copy of the License at
@@ -12,32 +12,18 @@
12 * See the License for the specific language governing permissions and12 * See the License for the specific language governing permissions and
13 * limitations under the License.13 * limitations under the License.
14 */14 */
15-import router from '@system.router';
16 15 
17-@Entry16+{
18-@Component17+ "lockfileVersion": 1,
19-struct Second {18+ "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
20- private content: string = "Second Page"19+ "specifiers": {
21- 20+ "@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6",
22- build() {21+ "@ohos/hypium@^1.0.6": "@ohos/hypium@1.0.6"
23- Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {22+ },
24- Text(`${this.content}`)23+ "packages": {
25- .fontSize(50)24+ "@ohos/hypium@1.0.6": {
26- .fontWeight(FontWeight.Bold)25+ "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz",
27- Button() {26+ "integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ=="
28- Text('back to index')
29- .fontSize(20)
30- .fontWeight(FontWeight.Bold)
31- }.type(ButtonType.Capsule)
32- .margin({
33- top: 20
34- })
35- .backgroundColor('#0D9FFB')
36- .onClick(() => {
37- router.back()
38- })
39 }27 }
40- .width('100%')
41- .height('100%')
42 }28 }
43}29}
@@ -0,0 +1,27 @@
1+/**
2+ * Copyright (c) 2023 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+{
17+ "license": "",
18+ "devDependencies": {
19+ "@ohos/hypium": "1.0.6"
20+ },
21+ "author": "",
22+ "name": "previewtest",
23+ "description": "Please describe the basic information.",
24+ "main": "",
25+ "version": "1.0.0",
26+ "dependencies": {}
27+}