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 ee8e444aa71cf659eeafbeabeca710a9c9836bae..eaa2790369c80f574fa6090845e33a197ea4b309 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 f47dc0d98e975d872e8ed04b576f14eb59a8d262..0787542b503326aebc0313fa4893c1f2b23114fb 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