单元测试与Android Studio和摇篮? [英] Unit tests with Android Studio and Gradle?

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

问题描述

我如何添加单元测试到我的机器人工作室(的IntelliJ)容易吗?

How can I add unit tests to my Android projects in Android Studio (IntelliJ) easily?

要更确切的说:我想补充一个文件夹测试code(JUnit 4中),并从那里使用常规的安装JDK(而不是在Android仿真器)执行单元测试。 到目前为止,我添加文件夹测试/爪哇/我的模块,并增加了测试作为源组和JUnit作为测试依赖性:

To be more exact: I want to add a folder with test code (JUnit 4) and execute the unit tests from there using the regular installed JDK (not in an Android emulator). So far I added the folders 'test/java/' to my module and added 'test' as a source set and junit as a test dependency:

sourceSets {
  instrumentTest.setRoot('src/test')
}

dependencies {
  instrumentTestCompile 'junit:junit:4.+'
  // ...
}

当我现在选择的测试/ java文件夹的运行所有测试它给了我一个UnsupportedOperationException。

When I now select Run 'All Tests' on the test/java folder it gives me an UnsupportedOperationException.

我在想什么?你如何运行单元测试的Andr​​oid项目?

What am I missing? How do you run your unit tests for Android projects?

积分为一个插件,它的工作原理是Infinitest在Eclipse的建议 - 在那里我可以简单地保存类和它的单元测试自动执行。 : - )

Bonus points for a recommendation of a plugin that works like 'Infinitest' in Eclipse - where I can simply save a class and its unit test is automatically executed. :-)

PS:我不想使用<一个href="https://github.com/JakeWharton/gradle-android-test-plugin">https://github.com/JakeWharton/gradle-android-test-plugin由于该插件似乎是德$ P $已经pcated。

PS: I do not want to use https://github.com/JakeWharton/gradle-android-test-plugin since that plugin seems to be deprecated already.

推荐答案

我想答案应该是现在已经在机器人工作室1.1(和当前的摇篮插件)。 他们推出的单元测试支持。 它仍然是实验性的,但比我们的previous这里努力:) 请参见这里

I think the answer should be now already in Android Studio 1.1 (and current gradle plugin). They introduced unit test support. It's still experimental, but less so than our previous efforts here :) See here.

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

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