Run your Flutter integration tests for Android
Integration tests are used to test how individual code works together and to capture the overall performance of an app. The integration test package, provided by Flutter is used to write integration tests for your Flutter app.
Follow these steps to run your Flutter integration tests for Android:
Setup BrowserStack account
You need a BrowserStack username
and access key
. To obtain your access credentials, sign up for a free trial or purchase a plan.
Prepare Android Flutter app and test suite for testing
You need to build a Flutter app and test suite for testing. You can create Flutter applications and test suites using either Flutter cli
or gradlew
. The steps below show how to create apks using gradlew
.
Create an instrumentation test file in your application’s android/app/src/androidTest/java/com/example/myapp/
directory. Replace com
, example
, and myapp
with the values from your app’s package name.
Then, name this test file as MainActivityTest.java
or another name of your choice.
Update your application’s myapp/android/app/build.gradle
file to ensure it uses androidx’s version of AndroidJUnitRunner
and includes androidx
libraries as a dependency.
Use the following Gradle
commands to build an instrumentation test.apk
file(test suite) using the MainActivityTest.java
created in the androidTest
directory as mentioned in step 1.
Avoiding this step might result in No Tests Ran
issue on the dashboard.
If you want to create your APKs by incorporating optional Flutter parameters, start by executing the Flutter tests using the flutter cli in verbose mode. This allows you to view the Gradle command that is utilized internally for building the APKs.
For example, if you want to use --no-sound-null-safety
in your tests, run the following command:
Next, check for gradlew
execution in the logs. For the above command, we get a gradlew command in the logs something similar to the following. Use the command to build your apk files:
Upload your app
Upload your Android app (.apk
or .aab
file) to BrowserStack servers using the REST API request.
The following sample cURL command shows how to upload an app:
A sample response for the request is as follows:
{
"app_name":"Application-debug.apk",
"app_url":"bs://j3c874f21852ea50957a3fdc33f47514288c4ba4",
"app_version":"1.0",
"app_id":"j3c874f21852ea50957a3fdc33f47514288c4ba4",
"uploaded_at":"2022-05-12 07:27:54 UTC",
"expiry":"2022-06-11 07:27:54 UTC"
}
The value of the app_url
parameter in the response is used to specify the application under test when you run Flutter integration tests.
App upload takes a few seconds to about a minute, depending on the size of your app. Do not interrupt the curl command until you get the response.
Upload your test suite
Upload your test suite (.apk
) file, created in the previous step, to BrowserStack servers using our REST API request.
The following sample cURL command shows how to upload a test suite:
A sample response for the request is as follows:
{
"test_suite_name":"Application-debug-test.apk",
"test_suite_url":"bs://f7c874f21852ba57957a3fde31f47514288c4ba4",
"test_suite_id":"f7c874f21852ba57957a3fde31f47514288c4ba4",
"uploaded_at":"2022-05-12 07:32:41 UTC",
"expiry":"2022-06-11 07:32:41 UTC",
"framework":"flutter-integration-tests"
}
The value of the test_suite_url
parameter in the response is used to specify the test suite when you run Flutter Integration tests.
Run Android Flutter integration tests
After you upload your app and test suite to BrowserStack servers, send an API request to start the test execution as shown in the following sample cURL
request:
A sample response for the request is as follows:
{
"message" : "Success",
"build_id" : "4d2b4deb810af077d5aed98f479bfdd2e64f36c3"
}
The build_id
is used to uniquely identify your build in App Automate.
View test results
After you start Flutter integration tests execution using the REST API, visit the App Automate dashboard to view your test results, debugging logs, and overall test details.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!