使用自定义滚动视图时单元测试失败

时间:2019-04-01 06:53:25

标签: android android-custom-view robolectric custom-view

我有一个自定义的scrollview类,已经在我的代码(java和xml文件)中实现了它,并且工作正常,但是使用robolectric框架,该活动的单元测试用例失败(86从200失败)。测试。

错误

    com.my.android.AppTest.AppActivityTest > testSetInProgressTrue FAILED
    android.view.InflateException: XML file /home/MJ/build/intermediates/merged-not-compiled-resources/debug/layout/layout.xml 
    line `#`-1 (sorry, not yet implemented): Error inflating class com.my.android.widget.myScrollView
    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at com.my.android.utilility.MyLayoutPreloader.createActivityLayout(MyLayoutPreloader.java:62)
    at com.my.android.AppTest.AppActivityTest.setUp(AppActivityTest.java:95)

    Caused by:
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$createView(LayoutInflater.java:594)
        at android.view.LayoutInflater.createView(LayoutInflater.java)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$createViewFromTag(LayoutInflater.java:696)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$rInflate(LayoutInflater.java:755)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$rInflate(LayoutInflater.java:758)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$inflate(LayoutInflater.java:397)
        at android.view.LayoutInflater.inflate(LayoutInflater.java)
        ... 2 more

        Caused by:
        java.lang.ArrayIndexOutOfBoundsException: 264
            at android.content.res.TypedArray.getBoolean(TypedArray.java:213)
            at com.my.android.widget.myScrollView.<init>(myScrollView.java:55)
            at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            ... 2 more

    java.lang.NullPointerException
        at com.my.android.utilility.MyLayoutPreloader.activityCloseCleanup(MyLayoutPreloader.java:83)
        at com.my.android.utilility.MyLayoutPreloader.reset(MyLayoutPreloader.java:187)
        at com.my.android.AppTest.AppActivityTest.tearDown(AppActivityTest.java:127)

    com.my.android.AppTest.AppActivityTest > testIsLayoutNotEnabled FAILED
    android.view.InflateException: XML file /home/MJ/build/intermediates/merged-not-compiled-resources/debug/layout/layout.xml 
    line `#`-1 (sorry, not yet implemented): Error inflating class <unknown>
    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at com.my.android.utilility.MyLayoutPreloader.createActivityLayout(MyLayoutPreloader.java:62)
    at com.my.android.AppTest.AppActivityTest.setUp(AppActivityTest.java:95)

    Caused by:
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$createView(LayoutInflater.java:594)
        at android.view.LayoutInflater.createView(LayoutInflater.java)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$createViewFromTag(LayoutInflater.java:696)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$rInflate(LayoutInflater.java:755)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$rInflate(LayoutInflater.java:758)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java)
        at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$inflate(LayoutInflater.java:397)
        at android.view.LayoutInflater.inflate(LayoutInflater.java)
        ... 2 more

        Caused by:
        java.lang.ArrayIndexOutOfBoundsException: 264
            at android.content.res.TypedArray.getBoolean(TypedArray.java:213)
            at com.my.android.widget.myScrollView.<init>(myScrollView.java:55)
            at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            ... 2 more

    java.lang.NullPointerException
        at com.my.android.utilility.MyLayoutPreloader.activityCloseCleanup(MyLayoutPreloader.java:83)
        at com.my.android.utilility.MyLayoutPreloader.reset(MyLayoutPreloader.java:187)
        at com.my.android.AppTest.AppActivityTest.tearDown(AppActivityTest.java:127)

类似地,我的86项测试失败。使用此 com.android.tools.build:gradle:3.1.4 &测试框架为 org.robolectric:robolectric:4.0.2

0 个答案:

没有答案