Android的工作室+ Robolectric +摇篮类未发现异常 [英] Android Studio + Robolectric + Gradle Class Not Found Exception

查看:273
本文介绍了Android的工作室+ Robolectric +摇篮类未发现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载Robolectric戴克,摇篮工程从<一个href="https://github.com/robolectric/deckard-gradle">https://github.com/robolectric/deckard-gradle并导入到Android的工作室。

I downloaded Robolectric deckard-gradle project from https://github.com/robolectric/deckard-gradle and imported to Android Studio.

在我第一次运行时我得到了

On my first run i got

!!! JUnit version 3.8 or later expected:
    java.lang.RuntimeException: Stub!
      at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
      at junit.textui.TestRunner.<init>(TestRunner.java:54)
      at junit.textui.TestRunner.<init>(TestRunner.java:48)
      at junit.textui.TestRunner.<init>(TestRunner.java:41)

错误,我修正了这个来自.iml。

Error and i fixed this from .iml.

后来我:

Class Not Found "my test class"

我试过许多解决方案,我发现在谷歌这个问题,但没有一次成功。

I tried dozens of solutions which i found in google about this problem but none of them worked.

推荐答案

更​​新:Android的工作室1.1.0增加了JUnit 4中,测试支持到IDE中。 https://sites.google:在查看更多.COM / A / android.com /工具/高科技文档/单元测试支持。这应该修复STUB例外。

UPDATE: Android Studio 1.1.0 has added JUNIT 4 testing support to the IDE. See more under: https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support. That should fix the STUB exception.

选项亚历克斯的一个是正确的答案:我现在在这两个项目使用它,它是可悲的,你必须这样做,这样一来,但是这就是你现在可以做

Option one of Alex is the right answer: I use it in two projects now and it is sad you have to do it this way but that's all you can do right now.

具体步骤如下:

  1. 当截线的例外是显示完全复制的第一个灰线到编辑器。
  2. 在这一行,删除-classpath一切最后的.jar入境前后的一切。 (像亚历克斯说,类路径,同时也删除后,它的其余部分)
  3. 搜索JUnit和移动类似以下内容之一行/path/in/filesystem/.gradle/caches/modules-2/files-2.1/junit/junit/4.11/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar:直接依赖的-classpath指令后开始。
  4. 添加你的测试类的输出目录像-classpath类路径的末尾/ dependency1:/ dependency2:/ ...:/用户/用户/路径/到/项目/应用程序/构建/测试类
  5. 进入运行配置,在下拉菜单,开始测试或应用程序
  6. 在JUnit测试配置(您想之前运行,而不是Android的测试),从上面添加文字为VM选项。
  7. preSS确定,运行测试,并瞧,它的工作原理!
  1. when the STUB EXCEPTION is shown copy the first grey line completely into an editor.
  2. In this line, delete everything before -classpath and everything after the last .jar entry. (Like Alex said, the classpath, but also delete the rest after it)
  3. Search for junit and move the line similar to the following one /path/in/filesystem/.gradle/caches/modules-2/files-2.1/junit/junit/4.11/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar: to the beginning of the dependencies directly after the "-classpath" directive.
  4. Add your test classes output dir to the end of the classpath like -classpath "/dependency1:/dependency2:/...:/Users/user/path/to/project/app/build/test-classes"
  5. Go to "Run Configurations" in the drop down menu where to start the tests or the app
  6. In your junit test configuration (which you tried to run before, not Android Tests) add the text from above as VM options.
  7. Press ok, run the test and voilà, it works!

顺便说一句,对于生成输出测试来源我不得不添加

By the way, for generating the output test-sources I had to add

apply plugin: 'idea'
idea {
    module {
        testOutputDir = file('build/test-classes/debug')
    }
}

到模块的build.gradle

to the module's build.gradle

如果你想使用的用户界面时,仍然得到错误,请转到包含在机器人工作室的终端,并使用./gradle清洁检查(或等效的命令),它运行皮棉检查项目和检查。如果有什么毛病你的测试,你会被告知那里有可能查看的HTML页面上的结果。

If you still get errors when trying to use the ui, go to the terminal included in android studio and use ./gradle clean check (or an equivalent command) which runs lint checks for your project and the tests. If anything goes wrong with your tests you'll be informed there and have the possibility to view the results on a html-page.

这篇关于Android的工作室+ Robolectric +摇篮类未发现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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