What is a good way to test onMeasure / onLayout / onDraw custom view methods?

I just wrote a custom View class, which, among other things, allows the developer to easily set borders (e.g. setBorderWidth , setBorderColor , setBorderWidthLeft , etc.). I did this by overriding onMeasure / onDraw , and I want to check that View is drawing these borders correctly.

Ideally, I want something at a higher level than unit test: basically I want to ensure that if I set the boundaries, they are drawn as expected; if I don’t install them, they are not drawn; if I change them, new borders will be drawn, and old ones will no longer be visible. This allows me to know that my opinion works at a high level.

Things I reviewed:

  • Taking a look in isolation with Robolectric and calling onDraw manually using the Canvas layout (doesn't check for invalidity though)
  • Creating a test example of Activity and somehow saving a screenshot of Activity and analyzing it programmatically.

None of them seem big to me, but I tend to 2). Any other ideas?

+6
source share
1 answer

For testing onDraw , onLayout and onMeasure screenshots-tests-for-android is a significant option.

0
source

Source: https://habr.com/ru/post/979067/


All Articles