Android Studio 0.8 中的单元测试 [英] Unit tests in Android Studio 0.8

查看:28
本文介绍了Android Studio 0.8 中的单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<块引用>

突发新闻:Android Studio 1.1.0 现在内置了对单元测试的支持.在此处查看更多信息:https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support

<块引用>

起初我知道有非常非常非常非常非常相似的问题(即使在这里也是如此).他们中的大多数已经过时了,所以我问了一个新问题,应该是最新的 Android Studio 0.8.x.

我知道有一些库以某种方式工作,但几乎在每种情况下我都没有证据表明信息是最新的.我知道有例如roboelectric,还有一些不推荐使用的 Jake Wharton,比如 gradle-android-test-plugindouble-espresso,我还找到了图书馆 RoboSpockDeckard.但它们似乎都没有任何 Android Studio 集成.

经过长时间的研究,我在所有实现中发现了这两个错误:

  • 类路径已损坏,需要破解才能运行 junit
  • junit 测试无法调试

我在找什么:

  • 我想自动测试一个算法(纯 java)
  • 我想检查我的 Android 应用中的集成是否有效
  • 我想要在 Android Studio 中进行集成,以便我可以从堆栈跟踪中跳转到代码中
  • 我想通过测试代码

我还在某处发现了一个不错的 hack,它在 gradle 中将测试作为外部任务运行并将结果推送到 AS 中以便可以显示结果,但不幸的是我找不到该链接(如果我没记错的话,它确实找到了)也不适合我).

你们有新的参考资料吗?对你有用吗?

解决方案

您必须编辑 Android Studio 生成的 .iml 文件以指向您的 test-classes 目录,并修复来自 Junit 的 Stub 错误.目前没有解决此问题的方法.

Gradlectric 是一个使用 Robolectric Gradle 插件 在 Android Studio 中运行单元测试.

BREAKING NEWS: Android Studio 1.1.0 now has built-in support for unit testing. See more here: https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support

At first I know that there are very, very, very much similar questions (even here on SO). Most of them are terribly outdated so I'm asking a fresh new question which should be up to date for Android Studio 0.8.x.

I know there are some libraries which work somehow, but in almost each case I had no evidence that the information were up to date. I know there is e.g. roboelectric, there are also some deprecated Jake Wharton like gradle-android-test-plugin or double-espresso, I also found the library RoboSpock and Deckard. But none of them seems to have any Android Studio integration.

After long reseach I found this two bugs in all implementations:

  • The classpath is broken and needs to been hacked to get junit running
  • The junit tests cannot been debugged

What I'm looking for:

  • I want to automatically test an algorithm (which is plain java)
  • I want to check the integration in my Android app works
  • I want an integration in Android Studio so that I can jump into the code out of a stacktrace
  • I want to step thrue the test code

I found also somewhere a nice hack which run the tests in gradle as an external task and pushed the results into AS so that the results could been displayed, but unfortunately I cannot find that link again (and if I remember correctly it did also not work for me).

Do you guys have some fresh references? Does it work for you?

解决方案

You have to edit the .iml file that Android Studio generates to point to your test-classes directory and also to fix the Stub error from Junit. There is currently no work around for this.

Gradlectric is a sample that uses the Robolectric Gradle Plugin to run unit tests in Android Studio.

这篇关于Android Studio 0.8 中的单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆