问题标签 [android-espresso]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1186 浏览

android - 启用使用主机 GPU 时,Espresso 测试冻结

我有一系列测试幻灯片菜单的 Espresso 测试。大多数测试在使用主机 GPU 开启时失败,但在禁用时不会。即使我禁用了动画,我想我可能在某处缺少设置,因为我仍然可以看到窗口滑动打开。我正在测试 Android 4.4.2 并使用 HAXM。为什么这个测试会失败?

这是一个测试示例(它们都具有相同的结构):

如果我在没有选中使用主机 GPU 的情况下启动我的模拟器,则测试通过。如果启用了使用主机 GPU,则第一个测试通过,然后其余测试失败,并显示:

我已经尝试在模拟器中禁用动画,如下所述:https ://code.google.com/p/android-test-kit/wiki/Espresso#Getting_Started ,但我仍然可以看到抽屉滑动打开和关闭。

0 投票
5 回答
5425 浏览

android - 使用 Retrofit 网络请求时如何使用 IdlingResource 测试 Android UI

我正在编写在 UI 中执行操作的集成测试,这些操作使用Retrofit启动网络调用。

我知道我需要实现 a CountingIdlingResource,但我想以正确的方式来做(如果已经完成,不要重新发明轮子)。

是否有人IdlingResource在其应用程序的Espresso测试套件中实现了等待网络请求执行的功能?

更多信息在这里

0 投票
1 回答
1075 浏览

android - 如何自动化安卓升级测试

我们一直在使用 espresso 进行 android 自动化,其中包括升级测试

对于升级测试,我们需要执行 3 个步骤:

  1. 在旧版本中做一些动作准备一些数据
  2. 升级到新版本(封面安装)
  3. 检查旧版本保存的数据是否正确保存,升级后没有其他问题。

目前我们正在以一种非常笨拙的方式进行操作:

我们将某个版本的升级测试分为之前/之后两部分,因为我们不知道我们是否能够(以及如何)在测试中安装新版本。

但是,adb 命令的这个 3 步测试看起来很愚蠢,而且我们不能轻易得到 junit 报告。

那么有没有人知道进行android升级测试的更好更简单的方法,或者你能指出我们做错了什么吗?

它不仅限于 Espresso,如果您正在使用其他框架,您如何使用它进行升级测试?

提前致谢。

0 投票
4 回答
12268 浏览

android - 在为 Android 进行 Espresso 功能测试时让 Dagger 注入模拟对象

我最近全神贯注于 Dagger,因为 DI 的概念完全有意义。DI 的一个更好的“副产品”(正如 Jake Wharton 在他的一个演讲中所说)是更容易测试。

所以现在我基本上使用 Espresso 进行一些功能测试,我希望能够将虚拟/模拟数据注入应用程序并让活动显示出来。我猜,这是 DI 的最大优势之一,这应该是一个相对简单的问题。但出于某种原因,我似乎无法绕过它。任何帮助将非常感激。到目前为止,这是我所拥有的(我写了一个反映我当前设置的示例):

这些是我的匕首模块:

在我的浓缩咖啡测试中,我试图插入一个模拟模块,如下所示:

这根本行不通。我的 Espresso 测试运行,但 TestNavigationModule 被完全忽略... arr ... :(

我究竟做错了什么?有没有更好的方法来用 Espresso 模拟模块?我已经搜索并看到了使用 Robolectric、Mockito 等的示例。但我只想要纯 Espresso 测试,并且需要用我的模拟模块换掉一个模块。我应该怎么做?

编辑:

所以我采用@user3399328 的方法来定义静态测试模块列表,检查空值,然后将其添加到我的应用程序类中。我仍然没有得到我的测试注入版本的课程。不过我有一种感觉,可能是匕首测试模块定义有问题,而不是我的浓缩咖啡生命周期。我做出假设的原因是我添加了调试语句并发现静态测试模块在应用程序类中注入时是非空的。您能否指出我可能做错的方向。以下是我定义的代码片段:

我的应用程序:

模块:

在我的测试类中修改了测试模块:

0 投票
2 回答
1452 浏览

android - 测试主屏幕小部件的最佳方法

测试 android 主屏幕小部件的最佳方法是什么?很难找到任何示例代码:/ 哪些框架支持该测试?

  1. 浓咖啡
  2. 机器人馆
  3. 其他
0 投票
3 回答
4226 浏览

android - 将活动发送到后台后如何重新获得对活动的访问权限

使用 Espresso,我尝试使用 Home 按钮测试将 Activity 发送到后台,然后再次将其置于前台进行一些检查:

我必须使用intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);由异常建议的,但除此之外我还测试了,将其作为启动器活动启动,或使用 FLAG_ACTIVITY_REORDER_TO_FRONT,但视图不可见。即使测试通过了。

0 投票
1 回答
1469 浏览

android - Android Espresso Synchronizing with Custom Resource

I want to use Espresso to test web calls. I've made a small test app to see if I can get this to work without using AsyncTask. Upon getting data back, a TextView tells the user whether the call was successful or not. I'm making the web call in a new thread.

In my test, I tried following the AdvancedSynchronizationTest as a pattern to making the test wait until the web request is fulfilled. My implementation, however, doesn't seem to work. My understanding is that the method that I'm overriding is ending before the callback is returned to the main activity. If that's the case, I'm overwriting the wrong class. I've also tried overriding runnable itself (see example below) and even changed the UI update to simply setting a boolean, but with no different outcome. Obviously, Espresso doesn't like my using another thread, but why doesn't it pick up that it should wait until the thread is complete? What would be an alternative without using AsyncTask?

You can see the whole project here: https://github.com/bqmackay/EspressoCustomThreadingResourceExample.

Here is the code in question:

MainActivityTest

DownloadHelper

MainActivity

0 投票
2 回答
24571 浏览

automated-tests - 如何使用 espresso 从 textview 获取文本

我想要在 LinearLayout 的 textview 中显示文本字符串。浓缩咖啡能做到吗?如果没有,是否有其他方法可以做到这一点,或者我可以在 espresso 测试用例中使用 android api 吗?我正在使用 API 17 18 或更新的 espresso 1.1(它应该是最新的。)。我对此一无所知。谢谢。

0 投票
2 回答
1962 浏览

android - 在 Android 仪器测试中给出 NoClassDefFoundError 的 Dagger 代码,但在普通应用程序中有效

我在 Android 应用程序中使用 Dagger。它在应用程序中工作,但是当我运行仪器测试时,我得到一个 NoClassDefFoundError。

我正在使用 Gradle 和 Espresso。这是在没有 progaurd 的情况下发生的。

这很奇怪,因为“Module$$ModuleAdapter”正在加载,但“Module$$ModuleAdapter$EndpointProvidesAdapter”没有。

我将 APK 拉出设备并使用 dexdump 验证该类确实在 APK 中,“Module$$ModuleAdapter$EndpointProvidesAdapter”。

关于可能导致这种情况的任何想法?

0 投票
1 回答
1353 浏览

android-espresso - 如何验证是否选择了文本

我需要验证是否选择了 TextView。这是对象:

is-selected当您选择 textview 时,从 false 变为 true。

在 Espresso 中有内置的方法吗?