测试通过 maven 和 adb 运行,但不是 IntelliJ - 为什么?
我正在开发一个使用 Maven 定义的项目,我可以成功运行 Maven 脚本来构建应用程序,并使用仪器在设备上运行自动化(junit 3.8.2)测试。
同样,我可以使用 adb 成功运行仪器测试。
然而,从 IntelliJ 运行仪器测试失败:
Running tests
Test running startedTest running failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
Empty test suite.
Logcat 将未找到的类显示为 org.junit.Test。 IntelliJ项目是通过导入根pom创建的,其他工作正常。我只需为测试创建一个运行配置,指定仪器运行程序。
我已经在多种设备上进行了尝试,它们都提供了相同的结果。
我希望 junit Test 类位于设备上的操作系统框架中,所以我很困惑为什么没有找到它。我尝试将 IntelliJ 中的 junit 依赖项从“提供”设置为“编译”,但这没有什么区别。
我错过了什么?
I'm working on a project defined with maven, and I can successfully run the maven script to build the app, and run automated (junit 3.8.2) tests on the device with instrumentation.
Likewise I can use adb to run the instrumentation tests successfully.
However running the instrumentation tests from IntelliJ is failing with this:
Running tests
Test running startedTest running failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
Empty test suite.
Logcat shows the not found class as org.junit.Test. The IntelliJ project was created by importing the root pom, and otherwise works fine. I just had to create a Run Configuration for the tests, specifying the instrumentation runner.
I've tried on several devices and they all provide the same result.
I would expect the junit Test class to be in the OS framework on the device, so I'm confused as to why it's not being found. I've tried setting the junit dependency in IntelliJ from Provided to Compile, but that makes no difference.
What have I missed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这是一个老问题,但是,与 intelliJ 相比,您很可能在 Maven 中拥有不同的类路径。您可以通过转到 intelliJ 项目结构(文件 --> 项目结构或 Ctrl + Alt + Shift + S)轻松解决此问题。
在“项目设置”下,单击“库”并手动添加缺少的库。
我确实觉得很奇怪,IntelliJ 没有获取 Maven 依赖项。毕竟,如果 Maven 运行它,那么 intelliJ 也应该运行它——它拥有 IDE 中最好的 Maven 集成,并且比 Eclipse 好得多。所以你的问题确实让我觉得根本原因是别的……
也许你可以问问IntelliJ的人?
您提供的更多信息可以让我们提供更好的反馈...
Okay this is an old question, however, most likely you'll have different classpath in maven as compared to intelliJ. You can solve this pretty easily by going to the intelliJ project Structure ( File --> Project Structure or Ctrl + Alt + Shift + S).
Under Project Settings, click Libraries and manually add the library that is missing.
I do find it strange though that IntelliJ is not picking up maven dependencies. After all, if maven runs it, so should intelliJ - it has the best maven integration available in an IDE and VERY VERY much better than that of eclipse. So your issue does make me feel something else is the root cause...
Perhaps you can ask the IntelliJ people?
More info on your part could allow us to give better feedback...