I wrote a Flutter Widget plugin with user interface automated testing using Android Studio based on Flutter documentation.
Tests execute properly but are quite abstract to write without following what happens on the device UI. All I see is that the test executes properly and the duration. The device is plugged and works properly but shows nothing related to the tests.
Is there a way to execute the UI tests from Android Studio and follow the execution on the device UI to simplify the writing of UI tests?
I would like to avoid using a solution based on screenshots as it would not be convenient to have to continuously open an image to follow what is happening.
As explained in the Flutter documentation, there are 3 types of tests:
Unit
Widget
Integration
Integration testing is the one that allows following the test execution on a device or a simulator.
Related
I had no problems before running my tests, but then I clicked on edit configuration to hide Hilt classes from code coverage and suddenly tests stopped working and this message started appearing.
I have tried everything in the related questions, but none of them seem to talk about this problem with code coverage and tests stopping running after modifying configurations. I can run tests for each package separately but if I try to right click on my unit test folder and click on run, I get the message all the time.
I am not using any test plugin or anything, just the standard Android Studio tests with Mockk and Truth as frameworks.
I'm running into an issue with the Android Studio Network Profiler. I can't see any of the network requests for my application. I'm currently using Retrofit 2. It seems the Profiler was built to work with OKHttp.
From my understanding Retrofit is built on top of OKHttp, so I'm not sure if there's something I'm missing to see the log data.
Version:
com.squareup.retrofit2:retrofit:2.5.0
It turns out that Retrofit will log in the Android Profiler. Unfortunately, in my case, the app was crashing during an initial network call. Despite launching the app in debug mode even with the debugger attached, it seems Android Studio didn't have enough time to fully initialize the Profiler and log any data.
I'm learning Flutter and using Android Studio as my IDE and i've hit some pain points around Integration Testing.
As part of the learning process i have written a basic Integration Test.
The intention with this integration test is to examine an Image widget (created via Image.Asset) to see if the image source, which is dynamically generated, is the expected value, or that an image is being displayed.
I run the integration test using the Terminal tab in the IDE, e.g: flutter drive --target=my_app/test_driver/user_list_scrolling.dart
I want to add a breakpoint to my Integration Test method and step through it from within Android Studio to help aid my learning of the testing functions.
My questions are:
How can i debug an integration test from within Android Studio? - As I'm learning i would love to put a breakpoint in my integration test and play around with the Finders in the immediate window. However, when i start my integration test from the terminal my Breakpoints seem to be ignored, i also tried adding the Debugger(); command. Execution paused, but i was unable to step through my code in Android Studio. I've also tried using the 'Attach to process' option in the IDE but the 'Choose process' list is empty.
Can i execute an integration test from within Android Studio without having to manually enter a command into a terminal? - i would rather click a button than memorise a command. Right-clicking my integration test file and selecting run does not appear to work.
How can i effectively test an Image widget from within an Integration Test? - The image source is set by calling Image.Asset() with a calculated value as the first argument, so i want to confirm that an image is displayed / the argument is the expected value. I'm guessing i need to use find.byType("Image") and somehow examine the result for the source value?
The following are the steps I took to set-up for integration test development using Flutter tooling, including debugging:
Configure the app to listen on a shared port (in this case 8888)
Add ‘— observatory-port 8888’ to ‘Additional Arguments’
Configure integration test to connect on the same shared port
Add ‘VM_SERVICE_URL=http://127.0.0.1:8888/’ to ‘Environment Variables’
Start the app in run or debug-mode (only required once, with hot-reload when needed):
Start the integration test in run or debug mode (as many times as you want):
You can now add breakpoints to the app and/or test and view source code and variables in debugger.
The following describes how to setup Android Studio to develop integration tests in more detail.
A how-to for fast integration test development with existing tooling
For some reason in Android Studio the icon to run in debug mode doesn't work with configurations scoped to entire directories. Create a configuration targeting one file, or simply click the "Run Test" icon in the gutter next to your main() function and select the "Debug" option.
With the new integration_test package you can just run flutter run integartion_test/app_test.dart to debug your tests.
My launch.json (I'm using VS Code):
{
"version": "0.2.0",
"configurations": [
{
"name": "Integration Test",
"request": "launch",
"type": "dart",
"program": "example/integration_test/app_test.dart",
},
]
}
You can run then the integration test from the AndroidStudio as you would run any other Flutter app (right-click on the file, run -> debug).
Sometimes the AndroidStudio identifies the file as Dart and not Flutter, so you have to create a new Run/Debug configuration for Flutter instead. At "Dart entrypoint", select the integration file with the "main" func.
I went to use hierarchyviewer and recieved the following message:
"The standalone version of hieararchyviewer is deprecated.
Please use Android Device Monitor (tools/monitor) instead."
So, I started up Android Device Monitor in Android Studio and could only find
"Dump View Hierarchy for UI Automator"
and it launches uiautomatorviewer in the Device Monitor...
Does anyone know if this means Google is intending to replace hierarchyviewer with uiautomatorviewer?
To start the Hierarchy Viewer from Android Studio:
Start Android Device Monitor
Click the Open Perspectives icon and select Hierarchy View.
Step 2
I used to use the hierarchyviewer in combination with monkeyrunner to do UI testing for android devices. Unfortunately, monkeyrunner was slow and limited and the tests were brittle.
I see the uiautomator as the better tool for inspecting UI elements. It has more powerful methods to identify UI objects and interact with them.
You no longer need to place sleep commands in your script. Just wait for a specific element. You can wait for an element to appear or disappear.
You can have watchers which run in case an UI object is not found. This can be helpful when handling pop-ups and error messages.
Here's a link to a tutorial.
http://developer.android.com/tools/testing/testing_ui.html
I did not see any official statement that says one replaces the other, but I think upgrading to uiautomator is the sensible thing to do. Hierarchyviewer and monkeyrunner are deprecated after all.
I'm trying to run unit tests in the build server of Visual Studio. Unfortunately, I get this message:
No test found. Make sure that installed test discoverers & executors,
platform & framework version settings are appropriate and try again.
I gave it a test setting files to run, specified the run settings, set the MSBUILD to x86 and the target platform to x86:
Emulator WVGA
Tried to specify the regex pattern to find the test DLLs. Still no luck. Am I doing something wrong ?
I'm using MSTest.
Edit: Apparently, I believe I mistakenly thought that Windows Phone Unit Test project is different from a Normal Unit Test Project. It was able to see the test sources when I just use normal unit test project. Correct me if I'm wrong. Question now is what's the point of the Windows Phone Unit Test App?
If you are using a third party test framework you will need to install it on the controller server.
Check this http://www.visualstudio.com/get-started/create-and-run-unit-tests-vs#frameworks