是否有可能测试与Robolectric一个抽象活动 [英] Is it possible to test an Abstract activity with Robolectric
问题描述
我在code使用抽象类的活动很好,抽象远离活动课的一些功能。
I use abstract activity classes in my code to well, abstract away some features from the activity classes.
我试图使用 Robolectric
和 gradle这个-Android的测试插件
来测试抽象活动课使用扩展抽象类的子类。我似乎无法得到它的工作,虽然。
I'm trying to test the abstract activity classes using Robolectric
and the gradle-android-test-plugin
using subclasses that extend the abstract class. I can't seem to get it to work though.
有没有人有任何这方面的经验,是它甚至可能吗?基本结构是:
Does anyone have any experience in this area and is it even possible ? Basic structure is :
@RunWith(RobolectricGradleTestRunner.class)
public class AbstractActivityTest {
private ActivityTest activity;
@Before
public void setUp() throws Exception {
activity = Robolectric.buildActivity(ActivityTest.class).create().get();
}
private class ActivityTest extends AbstractActivity {
// do something
}
}
起初,我得到了错误消息的子类是不是静态的,所以我使其静态的。现在我得到以下两个失败:
Initially, I got the error message the sub class wasn't static so I made it static. Now I get the following two fails:
initializationError FAILED
java.lang.Exception: Test class should have exactly one public constructor
initializationError FAILED
java.lang.Exception: No runnable methods
我把 @Test
方法中的任何明显的真正测试成功。
Any obviously true tests I put in @Test
methods succeed.
推荐答案
第一个错误是说你添加的非默认构造函数,以您的测试类或更改的访问级别默认值。但是,因为它说的JUnit
测试类应至少有一个公共构造函数。
The first error saying that you added non-default constructor to your test class or changed access level for default one. But as it says junit
Test class should have at least one public constructor.
第二个说,在测试类中的至少一种方法应该有 @Test
注释( JUnit 4中
)或测试子(的JUnit 3
)。
The second one says that at least one method in test class should have @Test
annotation (junit 4
) or starts with test substring (junit 3
).
这篇关于是否有可能测试与Robolectric一个抽象活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!