Skip to content

[Macrobenchmarks] - It is wrong to assume device.findObject() will always return the object. #711

Answered by SimonMarquis
SunnyBe asked this question in Q&A
Discussion options

You must be logged in to vote

IMO, we should never silently ignore this kind of null return value. This is definitely a bad testing practice and will hide potential bugs.
Unless there is a very good reason to handle it, for instance if we want to check 2 potential different code paths, you probably never should do that.

Unfortunately, UiAutomator has been designed in Java, and never received proper nullability annotations.
Although the Javadoc explicitly mention the potential null return value:

Returns the first object to match the selector criteria, or null if no matching objects are found.

This means that tests will fail with a semantically "wrong" NullPointerException on the next operation:

device.findObject(By.t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gptshubham595
Comment options

Answer selected by SunnyBe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants