相关疑难解决方法(0)

完全自定义阴影对象如何在Robolectric中工作?

如果我为我的Activity编写一个自定义Shadow,并使用RobolectricTestRunner注册它,那么框架是否会在我的自定义Shadow启动时拦截Activity?

谢谢.

android unit-testing robolectric

12
推荐指数
2
解决办法
8641
查看次数

如果存在自定义视图,Robolectric无法使布局文件膨胀

这是我的测试方法的样子:

@RunWith(RobolectricTestRunner.class)
public class TestMyApplication{
    private About aboutActivity;

    @Test
    public void AboutActivityTest() throws Exception{

        aboutActivity = new About();
        aboutActivity.onCreate(null);

        TextView aboutInfo = (TextView) sobreActivity.findViewById(R.id.text_version);
        assertThat(sobreInfo.getText().toString(), equalTo("My Application v1.0"));
    }

}
Run Code Online (Sandbox Code Playgroud)

aboutActivity.onCreate(null)行; 运行此测试时抛出以下异常

java.lang.RuntimeException: error inflating layout/about
    at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:106)
    at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:82)
    at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:86)
    at com.xtremelabs.robolectric.res.ResourceLoader.inflateView(ResourceLoader.java:336)
    at com.xtremelabs.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:43)
    at com.xtremelabs.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:48)
    at android.view.LayoutInflater.inflate(LayoutInflater.java)
    at com.xtremelabs.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:102)
    at android.app.Activity.setContentView(Activity.java)
    at br.com.About.onCreate(About.java:22)
    at br.com.MyApplication.AboutActivityTest(MyApplication.java:48)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at com.xtremelabs.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:269)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) …
Run Code Online (Sandbox Code Playgroud)

android unit-testing robolectric

5
推荐指数
1
解决办法
3420
查看次数

标签 统计

android ×2

robolectric ×2

unit-testing ×2