Running Flutter Integration Test in the Cloud

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
having texts especially having integration tests to check the most important and critical part of an application is crucial one of the challenges in flutter when it comes to running the integration test is running on different devices or sometimes an inconsistency of running an integration test from one you know machine to another machine what if we can run all of our integration tests in the cloud what if there will be a matrix of devices physical and virtual devices to test our applications in different format different version and different landscape or portrait mode in this session i'm going to show you how you can do this easily and integrate this into your cdci and leverage running integration tests in the cloud without any hesitation let's get into it my mj coffee app has several screens you can go to home page go to login page enter your username and password and then you can log in and see the menu screen this is exactly what we are going to write an integration test for and then run this integration test in the clouds to start open pub speak yml file and under dev dependencies install integration test package from sd clutter sdk then create an integration test folder in the root of your flutter application and under this folder you can create all of your integration tests for example i'm going to create app underline test to write my first integration test luckily writing an integration test with new with the new package is as similar as widget test so if you if you're already familiar with widget test in flutter then you're good to go let's get started we can write our first test widgets to test our flow from home page to login page and then to the menu screen to do that what we need to do is we need to make sure that the app is running in this test so i'm going to import my main application and then i'm going to call app.main to make sure that everything is running the first step would be then we need to make sure that the test is running we will wait a couple of seconds because the splash screen may take a few seconds to reload to the home page and then we make sure that we have the button ready so to recognize this button we can add a key that's what we already added to our login key so we can simply recognize this key in our test so then once it's recognized we can tap on this key as soon as this page is going to login page then we will also find our email and password with the key and we will enter one proper email and password then we hit the sign in button once the page is signed in we need to make sure that we are receiving respond and usually there will be a http request so maybe five seconds after that we're going to make sure that we are seeing a snack bar and menu screen and that means we already successfully logged into our application as of now the test is ready to run so we can simply run our test by saying floated test integration test folder and that will run all of our integration tests so far so good but that's what we don't want what we want is to run these integration tasks in the cloud on several different devices here is when the test lab on firebase is shining we need to set up our android and ios properly in order to make sure that our integration test can be run on firebase test lab to create an instrumentation test file in my application i need to create android test on the android folder and that needs to have a path to the package name of my app as a directory i can name the file as mainactivitytest.java file well you can change that to anything else if you want then the implementation of this file is fairly simple another thing that you need to do is you need to update your applications build gradle file to make sure that it uses android x version of android j unit runner and that has android x libraries as a dependencies too and finally to run the integration test i can run it on my local device or an emulated maybe a physical device with gradle w command line however this is not what we want we want to run it in the cloud well we can build our flutter application and then upload the apk to well of course firebase test lab but that's a manual process we want to make it automated let's get into it we'll start with creating a bash file named android integration.sh i'm going to make this bash file also executable later so then i can run whatever process that i have in one file i can use this file in any local machine or maybe in my cdci later we will do the same thing with ios later so the process is fairly simple we want to build or generate an apk for our android application then to run a test on android devices using 5s test labs we will use gradle command line to build an instrumentation test for android for linux and mac user make sure the ssh file is executable for windows user don't worry you can use powershell and you can do the same thing and then we can run the file and see everything is working properly to send these files to firebase automatically you need to have cloud sdks installed on the machine that you're going to run whether it's windows linux or mac once that's installed you can get access to gcloud command line luckily these steps are very simple you can find your firebase projects in the google cloud platform then you may go to iam and admin find service accounts open service account and find fibers admin sdk go to manage keys and then generate a key if you don't have make sure that is json format then you can store this key in the root of your application the next step is going to iam and find the firebase admin sdk and if you don't have editor role for these sdk try to add an editor role to the principal and finally go to libraries under apis and find cloud tools results api and make sure this api is enabled and the firebase project also make sure you have the project id you will get this under project settings one thing that you need to make sure is the json file the key that you downloaded make sure that is already in git ignore you don't want to publish this to public believe me next we need to make sure that gcloud is authenticating the service account that we created based on the key that we downloaded then we want to make sure that we are setting our project to the firebase project id that we grabbed from firebase console and finally running the firebase test android with gcloud command line and it will run the instrumentation test pointing to our application which we have created with flutter build apk command line that is enough however we will have more options to pass into this command line for example we can use orchestrator which will run the test more efficiently or time out or what if we can store the result of the test in some kind of storage in the cloud and we can reuse that wherever we want we can create our buckets in google cloud as simple as heading over to the google cloud finding a storage a cloud storage and then you go ahead and create a bucket one of the good thing about firebase test lab is to create a matrix of devices with different criteria to run our integration test we want to test in these devices not in our clients devices all right so what we can do we can definitely pass device ids os versions different locales or orientations and that will create a matrix of devices with different criteria you can receive all the devices that are available with different formats via gcloud command line choose whatever you want and create your matrix of devices it's time to run the test and see if it's working after everything is built and properly run then i go through the uploading phase and it goes and upload the apk to firebase test lab and that is fantastic because everything is automated right now after the test is running on all of the devices that i mentioned in firebase test lab i will receive a result back with either the test is failed or passed to my console heading back to the firebase test lab dashboard you will see all the tests that you are running you can go and check them out device by device and you can see all the tests that you have created either they are failing or passing or other information you have all the test cases performance tab you have also videos and logs available in the dashboard on top of that you also have access to test result folder which is going to forward you to the bucket that is storing all of this information as a file inside the bucket now that we have done android it's time to prepare our ios application so let's get started and open xcode you have to have a mac unfortunately for preparing your application for ios once you open your xcode on your mac go to file and create a new target we're going to create a new unique test in the target search for you need test and choose you need testing bundle make sure your product name is runner test and you can select the team add an identifier your language must be objective c and the target to be tested must be runner once everything is settled click on finish and create your test target it's time to add the target runner test to our pod file under ios folder in flutter make sure you run flutter build ios with config only pointing to the integration test once that's done the only thing that we need to do is we need to replace the runner test.m file with the suggested implementation from integration test it's also important you check the ios deployment target on the build settings for runner test and ensure that your target is the one that you want to test with for example in my case i have chosen 14.7 similar to android we're going to add our integration.sh5 in this file we're going to define our variables for example dev target which is 14.7 and then we will build our flutter ios application once that's done we need to make sure that we are running a xcode build to build for a test and then we are making sure that we are making our test zip file and ready to be uploaded to firebase test lab similar to android test we're going to run gc firebase test ios and we will run our test the zip file that we created we can also define our device models targets and locates and etc and definitely we can upload the result to our buckets you can get all the models of the ios version with the similar command but replacing android with ios that we've run for android all right now it's time to run the ios integration test and upload the file to firebase test lab and see how everything is going hopefully the test is passing as it did for android and we will get the result back from firebase test lab soon in our console all right now it's time to integrate to our cdci to run everything automated so what we want to do is we're going to we're going to create a workflow and have all of our steps under a mac os latest version we need to prepare for flutter as well as we need to use github actions for google cloud definitely we need to provide project id and service account key but you need to actually make sure you are providing your service account key with base64 and adding that to your repository under settings as a secret once that's done then you go ahead and add all of the scripts or both the scripts that you have created and voila everything is gonna work in cdci congratulations you created a matrix of devices running the integration test in the cloud and integrated with your cdci i really hope that you enjoyed this session so leave me a comment or let me know what you think you
Info
Channel: Majid Hajian
Views: 3,752
Rating: undefined out of 5
Keywords: flutter, firebase, integration test, flutter integration test, firebase test lab
Id: H4R8qiMksB0
Channel Id: undefined
Length: 16min 0sec (960 seconds)
Published: Wed Nov 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.