How to add Flutter integration test in a CI with GitHub Action ?
During the development of a project, we need something to make integration testing. And more importantly, use a CI to automatically run the tests. We will see in this article how to make our first integration test and use Github Action to perform the test in a workflow.
Tools we will need:
- Flutter => install here
- An account GitHub
Simple integration test
Before we deep dive into the CI workflow we need a simple integration test, to do so we will create a simple application with a test inside it:
flutter create integration_testing_with_ci
Then we create the test:
cd integration_testing_with_ci mkdir integration_test mkdir test_driver
First, we will create the
We can see here we add some code to handle the screenshot folder.
Next, we need the test itself
This is a simple test you can find in the official documentation.
You can now run the integration test locally with the command:
flutter drive --driver=test_driver/integration_test.dart --target=integration_test/increment_success_test.dart
You should find a screenshot inside
Subscribe to Etienne Théodore
Workflow Github Action
We will use GitHub to make our workflow. First, init your repository with
git init , then create your
.github/workflows/ folders with a file named
The most important action we will use is
reactivecircus/android-emulator-runner@v2, we can find the documentation here. It will run an emulator android and execute some script on it.
We will now create the workflow:
The most important in this workflow is the job "Run Flutter Driver tests", the action will start an emulator for us then execute the script provided and here we use the same command as before in local.
And finally, we upload the screenshots in artifact so we can check it later.
We just have to push the file into the repository and the workflow will be triggered:
And if you click on the workflow you should see something like this:
And inside the jobs we see some logs:
And after some minutes you should see:
And if you click on "Summary" you should see your artifact (screenshots):
We can see that our test pass successfully in the CI, and use the emulator provided by
Thanks to the matrix strategy we can also run the workflow for multi api levels for example this is a workflow with 21, 23, and 29 for target default and google_apis:
We just have to add in the yaml:
You can find all the possible configurations inside the documentation:
We use GitHub action and for the price, it's free for repositories public and we got 2,000 minutes/month for private repo.
All the prices can be found here:
With this workflow, we can now run integration testings directly in GitHub. And see the result/screenshots in an artifact.
Like always if you need to check the code take a look at my repository: