执行Robolectric JUnit 4测试用例

时间:2015-06-17 05:38:50

标签: android junit4 robolectric

我在执行Robolectric JUnit 4测试用例时遇到了initializationError 开发IDE:Eclipse Indigo 3.7.2

java.lang.NoClassDefFoundError: org/robolectric/annotation/Config

请在下面找到我的测试用例的源代码:

@RunWith(RobolectricTestRunner.class)
public class MainActivityTest {

    @Test
    public void clickingSplashVideo_shouldStartCategoryActivity() throws Exception {

        MainActivity activity = Robolectric.setupActivity(MainActivity.class);
        activity.findViewById(R.id.myvideoview).performClick();

        String hello = activity.getString(R.string.app_name);
        assertThat(hello, CoreMatchers.equalTo("Hello world!"));

        Intent expectedIntent = new Intent(activity, CategoryActivity.class);
        assertThat(Shadows.shadowOf(activity).getNextStartedActivity(), CoreMatchers.equalTo(expectedIntent));
    }
}

1 个答案:

答案 0 :(得分:0)

我刚刚通过添加 robolectric-2.3-jar-with-dependencies.jar 解决了这个问题,并从Android项目构建路径中删除了现有的 robolectric-3.0-rc3.jar