From 6e68a7c39e029fe38cc2e4d7b589093eddab68d6 Mon Sep 17 00:00:00 2001 From: s30030188 Date: Wed, 13 Aug 2025 20:04:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Daa=E5=B7=A5=E5=85=B7=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30030188 --- .../runner_runtime/js_test_runner.cpp | 4 +- .../ability_delegator/js_test_runner_test.cpp | 87 +++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/frameworks/native/appkit/ability_delegator/runner_runtime/js_test_runner.cpp b/frameworks/native/appkit/ability_delegator/runner_runtime/js_test_runner.cpp index ee8e444aa71..eaa2790369c 100644 --- a/frameworks/native/appkit/ability_delegator/runner_runtime/js_test_runner.cpp +++ b/frameworks/native/appkit/ability_delegator/runner_runtime/js_test_runner.cpp @@ -240,14 +240,16 @@ void JsTestRunner::ReportStatus(const std::string &msg) std::string JsTestRunner::GetTestRunnerPath(const std::shared_ptr &args) { std::string result; + result.append(args->GetTestModuleName()); if (!args->GetTestRunnerClassName().empty()) { - result.append(args->GetTestModuleName()); if (args->GetTestRunnerClassName().find("/") == std::string::npos) { result.append(LOWERCASETESTRUNNER); } result.append(args->GetTestRunnerClassName()); } else { + result.append("/"); result.append(args->GetTestRunnerPath()); + result.erase(result.rfind(".")); } return result; } diff --git a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/js_test_runner_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/js_test_runner_test.cpp index f47dc0d98e9..0787542b503 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/js_test_runner_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/js_test_runner_test.cpp @@ -327,3 +327,90 @@ HWTEST_F(JsTestRunnerTest, Js_Test_Runner_Test_0600, Function | MediumTest | Lev EXPECT_TRUE(iface_cast(shobserver)->testStatusFlag); } + +/** + * @tc.number: Js_GetTestRunnerPath_0100 + * @tc.name: ReportStatus + * @tc.desc: gettestrunner path + */ +HWTEST_F(JsTestRunnerTest, Js_GetTestRunnerPath_0100, Function | MediumTest | Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "Js_GetTestRunnerPath_0100 is called"); + + MockAbilityDelegatorStub::finishFlag_ = false; + std::map paras; + paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME); + paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS); + paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE); + paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT); + + Want want; + for (auto para : paras) { + want.SetParam(para.first, para.second); + } + + std::shared_ptr abilityArgs = std::make_shared(want); + + std::shared_ptr context = std::make_shared(); + std::unique_ptr testRunner = TestRunner::Create( + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + abilityArgs, + true); + sptr iRemoteObj = sptr(new MockAbilityDelegatorStub); + std::shared_ptr abilityDelegator = + std::make_shared(context, std::move(testRunner), iRemoteObj); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); + + sptr shobserver = sptr(new MockTestObserverStub); + abilityDelegator->observer_ = shobserver; + + JsTestRunner* pTestRunner = static_cast(static_cast((testRunner.get()))); + std::string path = pTestRunner->GetTestRunnerPath(abilityArgs); + TAG_LOGI(AAFwkTag::TEST, "Js_GetTestRunnerPath_0100 GetTestRunnerPath is called: %{public}s ", path.c_str()); + EXPECT_EQ(path, "ets/testrunner/JSUserTestRunnerjs"); +} + +/** + * @tc.number: Js_GetTestRunnerPath_0200 + * @tc.name: ReportStatus + * @tc.desc: gettestrunner path + */ +HWTEST_F(JsTestRunnerTest, Js_GetTestRunnerPath_0200, Function | MediumTest | Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "Js_GetTestRunnerPath_0200 is called"); + + MockAbilityDelegatorStub::finishFlag_ = false; + std::map paras; + paras.emplace(KEY_TEST_BUNDLE_NAME, VALUE_TEST_BUNDLE_NAME); + paras.emplace(KEY_TEST_RUNNER_CLASS, VALUE_TEST_RUNNER_CLASS); + paras.emplace(KEY_TEST_CASE, VALUE_TEST_CASE); + paras.emplace(KEY_TEST_WAIT_TIMEOUT, VALUE_TEST_WAIT_TIMEOUT); + + Want want; + for (auto para : paras) { + want.SetParam(para.first, para.second); + } + + std::shared_ptr abilityArgs = std::make_shared(want); + abilityArgs->SetTestRunnerModeAndPath("static", "mypatch.ets"); + + std::shared_ptr context = std::make_shared(); + std::unique_ptr testRunner = TestRunner::Create( + std::shared_ptr(ApplicationLoader::GetInstance().GetApplicationByName())->GetRuntime(), + abilityArgs, + true); + sptr iRemoteObj = sptr(new MockAbilityDelegatorStub); + std::shared_ptr abilityDelegator = + std::make_shared(context, std::move(testRunner), iRemoteObj); + AbilityDelegatorRegistry::RegisterInstance(abilityDelegator, abilityArgs, + OHOS::AbilityRuntime::Runtime::Language::JS); + + sptr shobserver = sptr(new MockTestObserverStub); + abilityDelegator->observer_ = shobserver; + + JsTestRunner* pTestRunner = static_cast(static_cast((testRunner.get()))); + std::string path = pTestRunner->GetTestRunnerPath(abilityArgs); + TAG_LOGI(AAFwkTag::TEST, "Js_GetTestRunnerPath_0200 GetTestRunnerPath is called: %{public}s ", path.c_str()); + EXPECT_EQ(path, "/mypatch"); +} \ No newline at end of file -- Gitee