Open pyricau opened 4 years ago
@adazh any thoughts?
It sounds reasonable to me to allow customization of the view hierarchy error renderer. I personally am not a huge fan of the default renderer either.
I am personally usually really cautious about adding extra dependencies. Would one option be to just directly modify the existing renderer (HumanReadables) to make it more useful?
Alternatively, androidx.test lately has been using ServiceLoader for this type of thing. HumanReadables could allow swapping out alternative implementations . Take a look at ServiceLoaderWrapper and its usages. Then there could be a solution where if radiography is on the classpath, Espresso will automagically use its renderer.
I am personally usually really cautious about adding extra dependencies.
Totally fair, I'd be cautious as well.
Would one option be to just directly modify the existing renderer (HumanReadables) to make it more useful?
It's always an option, but next thing you know we'll want to do even more and be back to exactly this spot.
If I understand the other options:
I have a personal preference for the latter but could make both work.
As for connecting Espresso + Radiography:
Radiography will be released this week or next.
It is a valid point about discoverability. API changes is another area are we are typically cautious about :) There is a process we follow where the different options are weighed and voted on. I can kick off the review process.
But first I wanted to clarify. Does Radiography require special initialization? I don't think content provider hacks should be needed. ServiceLoader already provides the classloading mechanism and ability to create an object with a default constructor. Radiography would just need to include resource metadata. Take a look at how Robolectric integrates with Espresso for an example: https://github.com/robolectric/robolectric/blob/master/robolectric/src/main/resources/META-INF/services/androidx.test.platform.ui.UiController
Does Radiography require special initialization?
Nope. I had forgotten about the ability to auto load services via resources. In that case, no need for any special init.
How do you deal with multiple services or customization? E.g. that radiography service might need to be customized.
Multiple services could be a problem. Depending on use case, you could either throw or just pick the first one but warn.
Lack of good customization options is another issue with the ServiceLoader approach.
One option is to support both ServiceLoader and a direct API that allows overriding the renderer. Then users who need customization, or want to ensure determinism wrt cases where there are multiple services have a fallback.
WDYT?
I like that!
Let me know how I can help. Happy to open PR, review, or whatever works for you.
Cool, can you start a PR?
@brettchabot there you go: https://github.com/android/android-test/pull/746
Description
@zach-klippenstein and I are working on releasing https://github.com/square/radiography , a utility that renders both Android & Compose view hierarchies to readable strings.
Espresso errors include a string rendering of the view hierarchy, unfortunately that rendering is not as human readable as it could be.
At Square, I've replaced Espresso's string rendering with the output from Radiography. I did that with a giant hack, setting a FailureHandler delegate and using reflection to replace the Throwable's
detailMessage
field 💩💩💩. Shared in a tweet here: https://twitter.com/Piwai/status/1291771701584252928It would be great if Espresso would provide a hook to set up a view hierarchy renderer. Also, if you feel comfortable with it, it could depend directly on Radiography in some way or offer it as an alternate impl (might be more involve to sign off on that?).
If you're ok with the idea of adding such an API I'm happy to open up a PR and we can take it from there.