diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/README.md b/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/README.md index 2e7233849b137990ac4086afe592be0e1b9f9905..0592669b5f863ae752138ceb63ee72fee1e7a7b3 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/README.md +++ b/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/README.md @@ -29,12 +29,23 @@ Copy StateMgmtTest.hap to local PC then: ```bash hdc install -r StateMgmtTest.hap ``` - Then run tests by clicking the application icon to start it. + Then run tests by clicking the application icon to start it. It will run all tests by default. + Cmd line to start the application without clicking the icon. ```bash +// Run all tests hdc shell aa start -a EntryAbility -b com.ohos.state_mgmt_ut + hdc shell aa start -a EntryAbility -b com.ohos.state_mgmt_ut --ps suite all + +// Run only V1 tests + hdc shell aa start -a EntryAbility -b com.ohos.state_mgmt_ut --ps suite v1 + +// Run only V2 tests + hdc shell aa start -a EntryAbility -b com.ohos.state_mgmt_ut --ps suite v2 + +// Run v1 and v2 tests. +hdc shell aa start -a EntryAbility -b com.ohos.state_mgmt_ut --ps suite v1,v2 ``` + Cmd line to close the application. diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/ets/entryability/EntryAbility.ets b/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/ets/entryability/EntryAbility.ets index 03de9ddeb4315b230a1965f1c50fd9f5e2024ef5..f687212b0f845ef83bcbde6ad73440fb3b93f508 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/ets/entryability/EntryAbility.ets +++ b/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/ets/entryability/EntryAbility.ets @@ -23,6 +23,10 @@ export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + + if (want && want.parameters) { + AppStorage.setOrCreate('suite', want.parameters['suite']) + } } onDestroy(): void { diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/ets/pages/Index.ets b/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/ets/pages/Index.ets index 3e13446941ec24d1a58d30a14a74b8c9f7e56249..7b769cb18a8aeea762a13652cd63f28ee64da92e 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/ets/pages/Index.ets +++ b/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/ets/pages/Index.ets @@ -22,6 +22,7 @@ import router from '@system.router' struct Parent { @State finalResult: string = "Pending..." @State finalResultsString: string = "" + @State suite: string | undefined = AppStorage.get('suite') reportFinal = (): void => { this.finalResult = TestStats.isAllPassed() ? "PASSED" : "FAILED"; @@ -33,16 +34,46 @@ struct Parent { } } - aboutToAppear() { - // Start after 200 ms to allow UI to start. - setTimeout(() => { - PageController.registerPages([ - 'pages/v1_tests', - 'pages/v2_tests', - // Add more pages if needed - ]) - PageController.start(this.reportFinal) - }, 200) +aboutToAppear() { + // Define available test pages + const suiteMap: Record = { + 'v1': ['pages/v1_tests'], + 'v2': ['pages/v2_tests'] + } + + let pages: string[] = [] + + // Check if we got suite as a start parameter + if( this.suite !== undefined) { + // Split the input string by comma and trim whitespace + const requestedSuites = this.suite.split(',').map(s => s.trim()); + + // Iterate over the requested suites + for (const suiteName of requestedSuites) { + + if(suiteName.toLowerCase() === 'all') { + pages = Object.values(suiteMap).flat() + break; // No need to check further, we want all tests + } + if (suiteMap[suiteName]) { + pages.push(...suiteMap[suiteName]); + } else { + console.error(`Unknown suite: ${this.suite}, running all`) + this.finalResult = + `Invalid suite type given: '${this.suite}'. Supported all, ${Object.keys(suiteMap).join(',')}` + pages.length = 0; + } + } + } else { + pages = Object.values(suiteMap).flat() + } + + if (pages.length > 0) { + setTimeout(() => { + PageController.registerPages(pages) + PageController.start(this.reportFinal) + }, 300) + } } build() { diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/resources/base/element/string.json b/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/resources/base/element/string.json index f94595515a99e0c828807e243494f57f09251930..171fbeaae9638fd73e86228e44bc0cdc7048dc29 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/resources/base/element/string.json +++ b/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/resources/base/element/string.json @@ -2,15 +2,15 @@ "string": [ { "name": "module_desc", - "value": "module description" + "value": "UnitTest" }, { "name": "EntryAbility_desc", - "value": "description" + "value": "UnitTest" }, { "name": "EntryAbility_label", - "value": "label" + "value": "UnitTest" } ] } \ No newline at end of file diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/resources/base/media/foreground.png b/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/resources/base/media/foreground.png index 97014d3e10e5ff511409c378cd4255713aecd85f..0d42f8e6ede4df275576721a705e584a7718dd51 100644 Binary files a/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/resources/base/media/foreground.png and b/frameworks/bridge/declarative_frontend/state_mgmt/test/unittest/entry/src/main/resources/base/media/foreground.png differ