我在嘗試驗證ListView
不包含特定項目。下面是我使用的代碼:Android Espresso onData with doesNotExist
onData(allOf(is(instanceOf(Contact.class)), is(withContactItemName(is("TestName")))))
.check(doesNotExist());
當名存在,我得到正確,因爲check(doesNotExist())
錯誤。如果名稱不存在,我得到以下錯誤,因爲allOf(...)
不匹配任何東西:
Caused by: java.lang.RuntimeException: No data found matching:
(is an instance of layer.sdk.contacts.Contact and is with contact item name:
is "TestName")
我怎樣才能像onData(...).check(doesNotExist())
功能?
編輯:
我有一個可怕的黑客拿到我用的try/catch和檢查活動的的getCause喜歡()的功能。我很樂意用一種很好的技術來取代它。
的文檔移動到這裏:https://開頭谷歌.github.io/Android的測試支持庫/文檔/咖啡/高級/#斷言,即,一個數據項 - 是 - 不在位的適配器 – friedger