Setup Code
Add package
TestSweets comes with its own Flutter package that allows all the magic to happen. Open up your pubspec.yaml
file and add the testsweets package.
Initialise TestSweets
After adding the package above we will do an internal TestSweets initialise. We do this by calling the setupTestSweets
function before we run the app.
If your main function is not async then you can make it async so we can call the setup function and await. Update your main function in main.dart
to look like this.
Using TestSweets Overlay UI
The Material and Cupertino app has a builder property you can supply. This allows us to add our testing tools ontop of your app.
Tracking the routes
The next thing we want to do is make sure TestSweets knows what view we are currently on. To do that we can add the TestSweetsNavigatorObserver
to the navigatorObservers
property.
If you’re using go_router you can add these observers to all your Shell Routes
Tracking Bottom Bar Navigations (optional)
This last part is optional. If you have bottom navigation and you swap out the views based on an indedx, it means that your view path won’t change when swapping tabs.
But we still need TestSweets to treat it as different views. To achieve that all we have to do is tell TestSweets when the tab has changed and pass in the index number.
To do that you can add the code below in the function
And with that we are 100% ready to start automating. 6 lines of code, and now your end-to-end testing can be done without writing any code additional code.