问题描述
在 roboelectric 中,当您编写测试类时,您已经声明了 @RunWith 注释,其中有 RobolectricGradleTestRunner 和 RobolectricTestRunner.class.有什么区别,我们应该使用哪一个?为什么首先有2个.如果我使用 RobolectricTestRunner 那么它对我不起作用它会显示一些奇怪的错误,例如:
In roboelectric when you write your test class you have declare the @RunWith annotation of which there is RobolectricGradleTestRunner and RobolectricTestRunner.class. What is the difference and which one should we use ? Why is there 2 in the first place. If I use RobolectricTestRunner then it does not work for me it says some weird error like :
"java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity."
但是,如果我使用 RobolectricGradleTestRunner,这似乎会消失.
However this seems to go away if I use RobolectricGradleTestRunner.
推荐答案
RobolectricTestRunner 是第一个,适用于基于 maven 的项目.
RobolectricTestRunner was first and is for maven based projects.
RobolectricGradleTestRunner 用于基于 gradle 的项目,因为某些路径已更改.从 robolectric 3.1.1 开始,这不再是必要的,现在已弃用.
RobolectricGradleTestRunner was for gradle based projects because some paths have changed.Since robolectric 3.1.1 this is not more necessary and is now deprecated.
欲知更多详情,另见http://robolectric.org/getting-started/
这篇关于RobolectricGradleTestRunner 与 RobolectricTestRunner.class的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!