Search code examples
androidandroid-espressoratingbar

How to set a specific rating on RatingBar in Espresso?


I'm trying to write an Espresso test that tests a RatingBar selection. How can I set a specific rating using Espresso? I only see click(), which always sets the middle rating.


Solution

  • You need to create a custom subclass of ViewAction that calls setRating on the view, then pass an instance of your custom view action to the perform() method.