Robot Testing is an end-to-end (E2E) technique that mimics a human. Its main advantage is that it focuses on the WHAT and not the HOW we are testing it. When a requirement changes or as our project or application envolves, we can continue to use the robot tests and its components. Yootube video : https://youtu.be/L7sJGihkNr8
Let’s see a sample of a testing scenario with the Robot Pattern :
Setup for integration tests
We use the
integration_test package for writing integration tests. Add the plugin to your
pubspec.yaml file as a development dependency
Using Robot Pattern for testing
Instead of writing all the tests in one file, we basically create robots per screen and then use the integration testing tools to test our application.
Take a look to the file ‘home_screen_robot.dart‘ already created lib/integration_test/robots/home_screen_robot.dart into our project flutter App
Note : Every robot takes in the WidgetTester as a constructor parameter and defines the methods as required by that screen
app_test.dart we initialize the HomeScreenRobot y DetailScreenRobot
and inside the
testWidgets function we can use the methods as per the behavior
Test the App
To run our integration tests, first, make sure the emulators are running, and then we run the following. Then you have some ways to run the test.
1. Go to the terminal (I’m using VSCode) write there this :
flutter drive \ –driver=test_driver/integration_test.dart \ –target=integration_test/app_test.dart
2. Create a scrip file integration_test.sh. The content will be the command : flutter drive \ –driver=test_driver/integration_test.dart \ –target=integration_test/app_test.dart
3. If you are using VSCode (like me!!) go to left panel and click on icon ‘testing’, you will find on the left , the list of tests that you’ve already created
Robot testing is an additional step that can increase the confidence in your ability to release your product to the market,
as well as decrease the cost and amount of manual testing needed, especially when there are regular releases that need to be tested.