Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running all flutter unit tests from Android Studio

I used to be able to run all my Flutter unit tests from the Android Studio GUI by right clicking on the tests directory and clicking on "Run 'tests in my_app'". After deleting and recloning my app directory (and maybe along with a combination of something else), I see this in the run log after attempting to run the tests:

Testing started at 8:42 AM ...
C:\flutter\bin\cache\dart-sdk\bin\pub.bat run test -r json C:/Users/me/AndroidStudioProjects/my_app
Observatory listening on http://127.0.0.1:2397/S0P_H2wKVSE=/

The Flutter SDK is not available.

Process finished with exit code 1

My SDK is setup properly because I can run and debug the app from Android Studio. If I run flutter test from the terminal tab in AS, the tests are executed successfully.

like image 633
user2233706 Avatar asked Jul 13 '20 12:07

user2233706


People also ask

How do I test my flutter app on my Android?

Set up and deploy Flutter apps on your Android device Using a USB cable, plug your phone into your computer. If prompted on your device, authorize your computer to access your device. In the terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device.

What is Flutter_test?

The flutter_test package provides the following tools for testing widgets: The WidgetTester allows building and interacting with widgets in a test environment. The testWidgets() function automatically creates a new WidgetTester for each test case, and is used in place of the normal test() function.

How to run flutter test in Android Studio?

You can either run through command line or use Android Studio ’s run configuration to setup flutter test configuration and run. I am going to show you the latter. In Android Studio, go to Run -> Edit Configurations. On Left hand section of the configuration screen, click on + icon and select Flutter Test configuration.

What are the different types of testing in flutter?

There are three types of tests that Flutter supports. A unit test verifies the behavior of a method or class. A widget test verifies the behavior of Flutter widgets without running the app itself. An integration test (also called end-to-end testing or GUI testing) runs the full app.

How do I run a flutter unit test in IntelliJ?

This is the Flutter plugin parsing your unit test code and inserting handy ‘run test’ actions directly into your editor. From IntelliJ or Android Studio, click on the ‘run’ icon and select either the option to run or debug your test: The tests will run, and the results will be displayed in the standard IntelliJ test result view:

How to write your first widget test in flutter?

I am going to talk about widget tests, how to write your first widget test, run the test from Android Studio by editing run configurations and see the test results under Run tab. In order to start writing our first widget test, we first need to look into the flutter_test package that comes in-built with Flutter SDK.


1 Answers

Good question,
I haven't found an answer yet, but I was able to define a new run configuration to run all my tests that were under "test" directory.

menu-->Run-->Edit configurations

Add a new configurations --> Flutter Test

Configuration:
Test scope: All in directory
Test directory: <your test directory>.
For example on my ubuntu: /home/MyUser/AndroidStudioProjects/MyApp/test

like image 177
A-Palgy Avatar answered Oct 21 '22 23:10

A-Palgy