2

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.

1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.