Android 基于事件的测试
我正在使用 robotsium 进行测试,并且遇到了一系列计时问题,这些问题使我很难知道活动(或视图)何时完成加载。因此,我正在编写的测试不是很稳健。
我正在寻找一种方法来使用可以推送到测试框架的事件来检测我的测试应用程序。如果我的被测应用程序可以在预期事件发生时“告诉”我的测试,这将非常有用。我在 Windows\Windows Phone 中使用了 Windows 事件跟踪过去效果很大。
我正在寻找的穷人执行此操作的方法是让我的测试应用程序实时读取 logcat 并在发生预期事件时通知测试。
还有人有其他想法吗?
I'm using robotium for testing and I'm running into a bunch of timing issues that are making it difficult for me to know when an activity (or view) is done loading. As a result the tests I'm writing are not very robust.
I'm looking for a way to instrument my application under test with events that can be pushed to the test framework. If my application under test could "tell" my tests when an expect event occurs, this would be very useful. I've used Event Tracing for Windows for windows\windows phone in the past to great effect.
The poor mans way of doing this that I'm looking at is to have my test application read the logcat in realtime and notify the test when an expected event occurs.
Does anyone have any other ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了解决这个问题,我依靠操作系统 logcat。我使用跟踪消息检测正在测试的代码部分,并等待它们在测试代码中出现。它可能不是最高效的做事方式,但它适合我的需求。我首先尝试创建一个从 logcat 读取的异步任务,但遇到了计时问题。我最终实现了这样的东西:
EventManager 代码(我将其包装在名为 EmSingleton 的单例中):
您需要在应用程序中设置以下权限:
我还创建了一个 LogEvent 对象来解析来自 logcat 的事件:
To solve this I'm relying on the OS logcat. I instrument portions of the code being tested with trace messages and wait for them to occur in the test code. Its perhaps not the most performant way of doing things, but it suits my needs. I first tried to make an asynctask that read from the logcat, but ran into timing issues. I finally implemented something like this:
EventManager code (That I wrapped in a singleton called EmSingleton):
You'll need to set the following permission in your application:
I also created a LogEvent Object to parse events coming from the logcat: