问题标签 [android-testing]
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.
android - Android 测试项目 - 从正在测试的活动接收事件?
是否可以使用从主要活动生成的 android 项目接收事件?
所以我可以测试事件?
这是测试事件的最佳方式吗?
提前致谢
android - Robolectric,单击列表项的问题
我一直在努力解决这个问题,我认为我没有得到关于 Robolectric 的基本知识。通常一些谷歌搜索可以帮助我深入了解这类问题,但在此之间并查看示例代码我没有找到任何有用的东西。
我正在尝试模拟单击列表视图项并检查单击后是否启动了活动。我不断地回想我正在测试的当前活动是结果活动。我尝试删除所有列表项单击代码并检查结果活动,这作为我正在测试的 InstallationListActivity 回来了。所以我得出的结论是列表视图项没有被点击,我只是不知道为什么。我在下面的测试代码中设置的系统日志是我期望的值。该列表有 13 个项目,getChildAt(0) 返回标题。我认为获取第一个项目 (getChildAt(1)) 并在其上调用 performClick 或其子文本视图会启动我预期的活动,但似乎并非如此。反正,
这是我用来构建列表视图的布局:
这是初始化列表的代码:
任何帮助深表感谢!万分感谢!
android - Android 单元测试以测试是否在 onCreate() 中调用了 setContentView()
已经搜索了一段时间,但找不到答案。假设我有这样的 onCreate 方法活动:
我有一个扩展 ActivityInstrumentationTestCase2 的测试类。在测试中的活动上调用 onCreate(null) 后,如何测试是否调用了 setContentView 并将其设置为正确的资源?
android - 如何在运行时为 Android UI 组件注册 EventListener
我正在为一堆 Android 应用程序编写测试程序。我计划首先在屏幕上获取所有视图对象(不是 ViewGroup 的实例),然后针对它们触发事件(通过 robotium 或 sdk 提供的方法)。问题是,我不知道向这些视图对象注册了哪种 EventListener。我尝试对所有这些对象触发 CLICK,但是对于 LongCLICK、flip、doubletap等还有很多其他的事件处理程序。那么无论如何我可以在运行时为Android UI组件注册EventListener吗?
android - Android SpinnerActivityTest 出现奇怪的 NullPointerException
我最近在 androids 开发者网站上使用 Activity Testing Tutorial。按照添加 UI 测试的分步指南 - 1. 您将获得以下代码片段:
怎么会这样?
我已经弄清楚了一些事实:
- 调试 TestApplication 时不会发生(即使没有断点)
- 当您发送 UI 线程休眠几毫秒时,它不会发生
- 当您直接在 mActivity.runOnUiThread() 之前记录 mSpinner 时,它永远不会为空(即使您得到 NullPointerException),但确实是当您将它记录在 Runnable 中时。
//编辑:添加 System.outs + stacktrace:
android - getActivity() 方法在单元测试时无限期阻塞
我正在尝试测试两个不同的Activity
类,其中一个Activity
恰好调用另一个。这是我的代码,然后我将解释问题:
介绍活动测试
根活动测试:
在IntroActivityTest
中,如果来自的用户令牌SharedPreferences
不为空,则立即开始RootActivity
。如果它为空,它会保持在IntroActivity
. 问题是,如果它不为空,则第一个测试 ( IntroActivityTest
) 通过,然后它挂在getActivity()
方法调用上RootActivityTest
,测试只是冻结...没有异常,它只是挂在该行上。如果用户令牌为空,它会完全正常运行这两个测试。
这可能是什么原因造成的?从观察来看,似乎RootActivityTest
正在尝试使用RootActivity
从 开始的IntroActivity
,但它不应该开始自己的实例RootActivity
吗?
android - Create folder in Instrumentation context
I am writing instrumentation tests for my app and want to create a temporary folder to store some files. However, I dont want to do that in the targetContext but rather in the test context.
In other words:
I've tried a bunch of other stuff, it seems as if the Instrumentation
context
implementation ignores these calls?
Thoughts?
java - 如何 JUnit 测试 IntentService
我是 Android 测试的新手,我想测试一个 IntentService,我目前正在扩展 ServiceTestCase。
我正在尝试使用 aResultReceiver
但问题是OnReceiveResult
在测试用例中从未调用过。(我也尝试创建ResultReceiver
withnew Handler()
作为参数 insetad ,null
但结果相同。
我究竟做错了什么?测试的正确方法是IntentService
什么?
这是服务:
}
这是测试:
android - How to test an IntentService using a ServiceTestCase?
I have been trying to test my IntentService
using the Android provided ServiceTestCase
class, but the tests fail with the testServiceTestCaseSetUpProperly
failing in the first place. My code follows:
What happens when I try to run this test with JUnit is this:
Even though I have gathered that testing Android IntentServices especially daunting, the testServiceTestCaseSetUpProperly
test is failing which means(according to Android docs) that my service failed to initialize a Context properly. How do I do that? If that is not the case (as I do initialize a Context using setContext()
in setUp()
), what can be done to work around this?
Also, I would highly appreciate someone pointing me to a link that provides general guidelines to Android service testing(with example implementation, of course).
android - 如何正确学习Android测试?
有哪些学习安卓测试的好方法?我对学习 Android 测试很感兴趣,我实际上并不做 TDD,而是一起编写测试和代码。
我阅读了http://developer.android.com/tools/testing/index.html 上的所有信息和“Android 应用程序测试指南”一书并理解了基本概念,但几乎没有我可以提供的信息或示例寻找。
这本书和示例非常基础,展示了如何使用 2 个 EditText 框测试一个非常简单的活动,
我需要测试更复杂的东西,例如 IntentService、AsyncTask、ResultReceiver 等。我有兴趣以 TDD 或几乎 TDD 的方式构建我的应用程序。
有什么方法可以让我学习这些东西(书籍、博客、示例……)或者 Android 测试非常罕见?