Espresso NoMatchingViewException when using withId matcher

前端 未结 2 1942
广开言路
广开言路 2021-01-02 09:21

I\'m trying to write a simple test where I simply click on a MenuItem that is in the main activity:

public class doTest extends ActivityInstrumentationTestC         


        
2条回答
  •  忘掉有多难
    2021-01-02 09:59

    haffax's answer is right. The menu item and the View generated for the menu have different IDs. Using withText is the best known practice in this case.

    To avoid hardcoding a text like 'Add new' in your test, I would recommmand using a String reference. E.g.,

    
    

提交回复
热议问题