Espresso - How to check if one of the view is displayed

后端 未结 10 2025
心在旅途
心在旅途 2021-02-03 17:22

In my test, after one action, there are two possible views which can appear and both of them are correct. How can I check if one of the view is displayed. For a single view I ca

10条回答
  •  时光说笑
    2021-02-03 17:34

    When I face this situation I generally split into multiple tests. One test sets the conditions for view #1 to be displayed and the other test sets the conditions for view #2 to be displayed.

    But let's say that you can't really control the conditions. For example, what if it depends on a random number or it depends on a third-party resource such as a calculation on a server? In that case, I usually solve the problem mocking. That way I can control the conditions so I know exactly which view to expect. I use Dependency Injection to set the mock I need for each test.

提交回复
热议问题