rozeri dilar
rozeri dilar

Reputation: 381

How to create UI tests with Espresso Test Recorder for programmatically created views

I am currently using Espresso testing framework in our app. Everything goes well when I use it with XML created views. However, it does not work with most of our views which are programmatically generated custom views(We do not use XML mostly). Do you have any idea how can I create test cases for custom views?

The main screen of the app is basically a maps screen(we use mapbox) where it shows places(it takes approximately 2 seconds to show them). It is similar to google maps app when you search restaurants. I want to match a view after it is being rendered. Can I create a test case like test this view after it is being rendered or at least test this view 3 seconds after it is being created?

I have already looked Testing custom Views with Robolectric, but I wonder if there is a way to do tests with Espresso testing framework.

Upvotes: 2

Views: 293

Answers (1)

Martin Zeitler
Martin Zeitler

Reputation: 76579

There is absolutely no difference in between framework, androidx and custom views, simply because they all extend on View.

AndroidX Test & Espresso have further modules one can load and Espresso also supports custom ViewMatcher, where one can reach just any node in the layout.

If you're trying to match a view before it is being rendered, the test might not be setup properly (the XML content view is just usually rendered early and so it's nodes can be matched early). The question is too abstract to tell why it doesn't match these views.

See https://developer.android.com/studio/debug/layout-inspector

Upvotes: 1

Related Questions