I am new to Robolectric and am at a roadblock. I have some custom event that fires on selection of a item in spinner and i want to test that using robolectric. I saw that ShadowSpinner class provides helper function like stateSpinner.clickFirstItemContainingText to click a particular item. I populate my spinner with proper values which i test printing out each item as
for (int i = 0; i < spinner_items.length; ++i) {
spinner_items[i] = (String) spinner.getAdapter().getItem(i);
}
System.out.println("Spinner Items "
+ Arrays.asList(spinner_items).toString());
However when i use clickFirstItemContainingText with one of the po pulated values, i get a IllegalArgumentException. No item found containing test which is strange as above code shows that particular value do exists.
Any help would be greatly appreciated
I couldn't get Robolectric to work with spinners. The problem is that the views for the list-items in the spinner won't exist apart from the one selected. This can be seen as spinner.getChildCount()
will always return 1. Just call spinner.setSelection()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With