【问题标题】:How to test DeepLinks with espresso如何用 espresso 测试 DeepLinks
【发布时间】:2018-01-31 23:29:04
【问题描述】:

我想为我的所有深层链接添加测试,以启动它们并查看所需的活动是否已启动并断言该活动上显示的内容。

我该怎么做?

编辑

我最终只测试了https://medium.com/@singwai/testing-deep-linking-with-espresso-and-burst-5e1bdb3c5e29 所说的深层链接匹配。

在科特林中:

@Throws(Exception::class)
fun test_deepLink_isResolvedBy(url: String, canonicalActivityName: String) {
    val appContext = InstrumentationRegistry.getTargetContext()
    val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
    val resolvedActivities =
        appContext.packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL)

    val resolverActivityMissing = resolvedActivities.none {
      it.activityInfo.packageName == appContext.packageName &&
          it.activityInfo.name == canonicalActivityName
    }

    if (resolverActivityMissing) {
      fail("$url is not resolved for $canonicalActivityName")
    }
}

然后我检查是否有活动可以解析我的网址,并在自己的测试中测试每个活动。

【问题讨论】:

  • 我已经在这里回答了同样的问题:stackoverflow.com/questions/44074173/…希望对您有所帮助!
  • @Caipivar 你搞定了吗?
  • @JohnO'Reilly nope
  • 我认为您尝试了下面的launchActivityWithIntent 代码....我正在使用相同的代码来做您正在尝试的事情,所以很好奇您在使用它时仍然看到什么问题?

标签: android android-intent android-espresso


【解决方案1】:

应该可以使用如下内容:

launchActivityWithIntent(getActivity().getPackageName(),
        YourActivityThatHandlesDeepLink.class,
        new Intent(Intent.ACTION_VIEW).setData(Uri.parse(link)));

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多