Instrumentation Testing: Robot Pattern - devrath/RunTracer GitHub Wiki

robotic-workshop1692882236

What is the use case for using a robot pattern

  • Consider a scenario where there is a check-box and we have a logic that sets it checked/not-checked based on logic.
  • Now if we change the check-box to a image-view then a lot of things need to be modified.

Solution - Separate what from how

  • By separating the what and the how our tests are more maintainable.
  • In the above example,
    • What -> whether the checkbox needs to be checked.
    • How -> whether the widget is checked.

Robot Pattern

  • This pattern exposes an API that separates the what and the how.
  • By separating the actions (robot) from the assertions (tests), the Robot Pattern ensures that tests are easier to read and maintain.

Structure

Robot Class

  • This contains methods that interact with UI elements.
  • The method corresponds to action on the UI such as clicking a button or entering text.

Test Class

  • This contains actual test cases that use the robot class to perform action and verify outcomes.

Advantages of Robot Pattern

  • Test cases are more readable.
  • The entire logic is encapsulated in a separate place, so if the UI changes then we just need to modify the test case in one place.
  • They can be re-used in other places if needed