How to run integration tests on Flutter apps
On This Page Introduction To FlutterFeatures of Flutter Framework
Flutter, designed by Google, is a free and open-source framework for building visually appealing, natively collect, and multi-platform applications from a individual codebase. Flutter has become rather democratic due to its power to create multi-platform apps. It enable users to build, deploy, and test web, mobile, desktop, and embedded application from a single codebase. Features of Flutter Framework: Steps To Perform Integration Testing In Flutter Apps This clause research the Flutter framework and how to run integration tests on Flutter apps. Flutteris an open-source mobile UI framework that can create Android and iOS apps (among other program) from a single codebase. Generally, frameworks offer different features to develop mobile application. For example, Android provide a framework based onJava and Kotlinto acquire mobile apps, whereas iOS uses a framework based onObjective-C or Swift language. As a result, Devs had to use two different languages and frameworks to develop applications for both OS. Naturally, a cross-platform framework like Flutter makes life simpler for them by saving resource, time, and effort. Here are some of the key features that set Flutter apart: Flutter support three types of tests: Unit tests and Widget tests can essay individual classes, widgets, or functions. However, they don ’ t verify how individual component work together or monitor application performance on real devices. This is where integration tests come in. Integration tryout in Flutter are written apply theconsolidation testpackage, provide by the SDK. This is Flutter & # 8217; s version of (generic web), Protractor (Angular),, or Earl Gray (iOS). The parcel internally usesflutter driverto drive the exam on a device. Tests written with theintegration_testpackage can: When Flutter was introduced, integration tests were written usingflutter_driver, which enable testers to sustain programmatic control of a Flutter app. On run the futter cause command, it initiates 2 processes: This allowed the developer to write tests in plain Dart that could interact with the app. However, it came with significant disadvantages: SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. The integration_test parcel was released to fix some of the issue mention above. Here, the code for tests runs in the same isolate as the app code itself. In other language, it can access the like memory. This basically resolves the previous issues, and offers a few early benefits: This example will demonstrate how to test a tabulator app. This establish how to set up integrating tryout, how to verify if a specific text is being displayed by the app, how to tap specific widgets, and how to run integration tests. In order to execute the Integration test, follow the below steps: Step 1. Create an app to test First, create an app for testing. This tryout will use a tabulator app produced by thedisruption createbid. This app will let a user tap on a button to increase one tally. Step 2. Add the integration_test dependency Now, use theintegration_test, flutter_driver, and flutter_testpackages for writing integration tests. Add these dependencies to thedev_dependenciessection of the app ’ spubspec.yamlfile. The location of the package should be the Flutter SDK. Step 3. Create the exam file Create a new directory,integration_test, with an empty-belliedapp_test.dart file: Step 4. Write the integration exam Now, compose the integration test with the measure below: Step 5. Run the integration exam The process of fulfill desegregation tests depends greatly on the platform used. If the program so permits, You can test on roving devices or web browsers. Mobile To test on a real iOS / Android gimmick, foremost, connect the device and run the following command from the root of the project: Or, specify the directory to run all integration tests: This command runs the app and integration tests on the target twist. Web To essay on a web browser (Chrome, in this example),Download ChromeDriver. Next, make a new directory namedtest_drivermoderate a new file namedintegration_test.dart: Launch WebDriver, for example: From the root of the project, run the next command: Here are some mutual mistakes to watch out for when writing Flutter integration trial: In order to get the virtually out of Integration tests, tests must be run on multiple existent device, program, and OS combination. You can not comprehensively and accurately identify all possible glitch without screen apps in, and that is where BrowserStack come in. BrowserStack ’ s offers K of real mobile devices from major vendor and manufacturers for app testing (manual and automated). Each device is loaded with existent operating systems – multiple versions of popular go systems in use. With BrowserStack, QAs can access yard of popular wandering device-OS combinations to essay their app and script their automation cases without worrying about purchasing and updating device and instal software. They just want to, choose the mandatory device-OS combination and start test their app. On This Page # Ask-and-Contributeabout this subject with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.How to run integration tests on Flutter apps
Overview
Introduction To Flutter
Features of Flutter Framework
Testing In Flutter Apps
Integration Testing In Flutter Apps
Migrating From Flutter Driver
Integration_Test Package
Steps To Perform Integration Testing In Flutter Apps
import 'package: flutter/material.dart ';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {const MyApp({Key? key}) : super(key: key);@overrideWidget build(BuildContext context) {return const MaterialApp(
title: 'Counter App ',
home: MyHomePage(title: 'Counter App Home Page '),);}
}
class MyHomePage extends StatefulWidget {const MyHomePage({Key? key, required this.title}) : super(key: key);final String title;@override_MyHomePageStatecreateState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {int _counter = 0;void_incrementCounter() {
setState(() {
_counter++;});}@overrideWidget build(BuildContext context) {return Scaffold(
appBar: AppBar(
title: Text(widget.title),),
body: Center(
child: Column(mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[const Text('You have force the button this many times: ',),Text(' $ _counter ',// Provide a Key to this specific Text widget. This allows// identifying the widget from inside the test suite,// and read the text.
key: const Key('counter'),
style: Theme.of(context).textTheme.headline4,),],),),floatingActionButton: FloatingActionButton(// Provide a Key to this button. This let chance this// specific button inside the test suite, and tapping it.
key: const Key('increment '),
onPressed:_incrementCounter,
tooltip: 'Increment ',
child: const Icon(Icons.add),),);}
}
# pubspec.yamldev_dependencies:integration_test:
sdk:flutter flutter_test:
sdk: flutter
counter_app/
lib/
main.flit integration_test/
app_test.dart
import 'package: flutter_test/flutter_test.dart ';
import 'package: integration_test/integration_test.dart ';
import 'package: introduction/main.dart ' as app;
void main() {IntegrationTestWidgetsFlutterBinding.ensureInitialized();group('end-to-end examination ', () {testWidgets('tap on the floating activity push, verify counter ',(WidgetTester tester) async {
app.main();await tester.pumpAndSettle();// Verifies that the counter starts at 0.
expect(find.text('0'),findsOneWidget);// Finds the floating action button to tap on.final Finder fab = find.byTooltip('Increment ');// Emulates a tap on the floating activeness button.await tester.tap(fab);// Triggers a frame.await quizzer.pumpAndSettle();// Verifies if the tabulator growth by 1.
expect(find.text('1'),findsOneWidget);});});
}
flutter test integration_test/app_test.dart
flutter examination integration_testimport 'package: integration_test/integration_test_driver.dart ';
Future& lt; void & gt; main() =>integrationDriver();
chromedriver--port=4444
flutter drive \--driver=test_driver/integration_test.dart \
--target=integration_test/app_test.dart \
-d web-server
Common Mistakes to avoid in Flutter Integration Testing
Integration Tests In Flutter Apps With BrowserStack
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously