Running automated tests
How to run automated tests in builds configured with the Flutter workflow editor
Codemagic supports running unit, integration and widget tests as well as static code analysis with flutter analyze. When testing is enabled, tests are run automatically every time your project is built. You can configure the test settings in App settings > Tests.
During the first build of your app, Codemagic will scan the repository’s content and automatically detect the tests according to the project structure. The expected locations of the tests are as follows:
Unit and widget tests:
Integration tests (Flutter Driver tests):
Running Flutter Driver tests
There are several options for running integration tests during the build. You can select one option per workflow:
- iOS simulator (selected by default)
- Android emulator
Devices available on the machine are:
For iOS and Android, it’s recommended to launch the desired emulator before the tests start:
flutter emulators --launch ios
flutter emulators --launch emulator
The recommended approach to running integration tests is to use
flutter test and the
integration_test dependency. To do so, navigate to App settings > Tests > Integration and unit tests and under Flutter drive arguments define the following:
To run only a specific test, the path has to be specified:
However, the above approach is not suitable for integration tests for web using
chromedriver, and the following arguments are recommended instead:
drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart
test_driverfolder with the
integration_test.dartfile beforehand is required, as per Flutter documentation.
Stop build if tests or analysis fail
If you check Stop build if tests or analysis fail, the build will stop after finishing all the enabled tests or analysis runs when any of them fail. Such builds will have the status “failed”.
Running tests in Firebase Test Lab
Integration tests can also be run on real devices in Firebase Test Lab when using the integration_test package and custom scripts in Codemagic. See a detailed guide on how to set up testing in Firebase Test Lab here.