VerifyError with ShinobiControls and Robolectric

140 Views Asked by At

I'm running into this strange VerifyError when trying to run Robolectric tests that call ShinobiControls under the hood. I've tried the -noverify option, but it doesn't seem to be working, or I'm putting it in the wrong place.

I'm using Retrolambda, Java 8, Robolectric (3.0), and Shinobi Premium (1.8.0).

java.lang.VerifyError: Expecting a stackmap frame at branch target 18
Exception Details:
  Location:
    com/shinobicontrols/charts/ChartFragment.onResume()V @8: ifnull
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0x0000000: 2ab7 000b 2ab4 0006 c600 0a2a b400 06b6
    0x0000010: 0012 b1                                

    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
    at java.lang.Class.getConstructor0(Class.java:3075)
    at java.lang.Class.newInstance(Class.java:412)
    at android.app.Fragment.instantiate(Fragment.java:611)
    at android.app.Fragment.instantiate(Fragment.java:582)
    at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2108)
    at android.app.Activity.onCreateView(Activity.java:5282)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
    at android.app.Activity.setContentView(Activity.java:2144)
    at com.example.android.MainActivity.onCreate(MainActivity.java:132)
1

There are 1 best solutions below

3
On

Basically, we are facking shinobi view. We have next construction:

public class ShinobyView {
    @VisibleForTesting
    @NonNull
    protected ChartView getShinobiChart(@NonNull final LayoutInflator inflator, @NonNull final ViewGroup chartContainer) {
        return inflater.inflate(R.layout.shinobi_chart, chartContainer, false);
    }

    @NonNull
    public View createView(@NonNull context context) {
       ...
       ChratView view = getShinobiChart(inflator, container);
       container.addView(view, <some layout params>);
       ...
    }
}

And in test we fake it:

public class TestShinobyView {
    @Override
    @NonNull
    protected ChartView 
    getShinobiChart(@NonNull final LayoutInflator inflator, @NonNull final ViewGroup chartContainer) {
        return new View(activity);
    }
}

If you want to verify that you also correctly setup shinobi charts then you need to mock ShinobiChart and return not View but faked ShinobiView