Search code examples
androidactionbarsherlockrobolectric

Action Bar Sherlock + Robolectric


We use Robolectric for our test cases at work which seems to not work well Action Bar Sherlock.

Problem is that I get a No implementations match configuration message, because the Build.VERSION.SDK_INT == 0 when run via robolectric.

If anyone has ideas on the best way of getting ABS working nice with Robolectric, I'd love to know. If I find out I'll post my results here, but it seems to be very hard to find information on how to make this popular toolkit and library work together.


Solution

  • Two ways to solve this:

    1. Change Robolectric's Build.SDK_INT value to a real value using this gross method call: RobolectricTestRunner.setStaticValue(Build.VERSION.class, "SDK_INT", 15);
    2. Write your own ActionBarSherlock implementation that extends from one of the existing ones and annotate with @ActionBarSherlock.Implementation(api = 0) (don't forget to call ActionBarSherlock.registerImplementation as well).