<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: TheNerdyGeek</title>
    <description>The latest articles on DEV Community by TheNerdyGeek (@thenerdygeek).</description>
    <link>https://dev.to/thenerdygeek</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F824570%2Fbf5059b2-e0db-48a3-a050-ba632bc8ac51.PNG</url>
      <title>DEV Community: TheNerdyGeek</title>
      <link>https://dev.to/thenerdygeek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thenerdygeek"/>
    <language>en</language>
    <item>
      <title>How to run parallel tests with CircleCI</title>
      <dc:creator>TheNerdyGeek</dc:creator>
      <pubDate>Thu, 17 Mar 2022 19:50:38 +0000</pubDate>
      <link>https://dev.to/thenerdygeek/how-to-run-parallel-tests-with-circleci-4dpk</link>
      <guid>https://dev.to/thenerdygeek/how-to-run-parallel-tests-with-circleci-4dpk</guid>
      <description>&lt;p&gt;More often than not, testers have to deal with a large codebase comprising hundreds or even thousands of tests. Most tests validating website or app functionality must be rerun on different platforms (devices, browsers, operating systems). &lt;/p&gt;

&lt;p&gt;However, running so many tests on different platforms can be immensely difficult, not to mention tedious and error-prone, without the right strategy and tech. The best and easiest way to test under such conditions is to use parallel testing. &lt;/p&gt;

&lt;p&gt;This article will explore how to run parallel tests with a particularly popular and useful CI/CD tool like CircleCI. &lt;/p&gt;

&lt;p&gt;But, first thing’s first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is parallel testing? &lt;/li&gt;
&lt;li&gt;How to run tests in parallel with CircleCI&lt;/li&gt;
&lt;li&gt;How to set up parallelism in CircleCI&lt;/li&gt;
&lt;li&gt;How to split test files using CircleCI CLI&lt;/li&gt;
&lt;li&gt;Globbing the tests&lt;/li&gt;
&lt;li&gt;Splitting the tests&lt;/li&gt;
&lt;li&gt;Split By Time&lt;/li&gt;
&lt;li&gt;How to split tests using environment variables&lt;/li&gt;
&lt;li&gt;How to run split tests&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is parallel testing?
&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://www.browserstack.com/guide/parallel-testing-with-selenium"&gt;parallel testing&lt;/a&gt;, you test different modules or applications on multiple browser-device-OS combinations simultaneously rather than one after another. In a scenario where we have two versions of software available, and both must be examined to ensure stability and compatibility, it is easier to run tests on two versions simultaneously, get results and detect bugs faster&lt;/p&gt;

&lt;p&gt;Parallel testing reduces execution time and effort, resulting in faster time to delivery. It is particularly useful in the case of &lt;a href="https://www.browserstack.com/live"&gt;cross browser testing&lt;/a&gt;, &lt;a href="https://www.browserstack.com/guide/cross-browser-compatibility-testing-beyond-chrome"&gt;compatibility testing&lt;/a&gt;, localization, and &lt;a href="https://www.browserstack.com/guide/internationalization-testing-of-websites-and-apps"&gt;internalization testing&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to run tests in parallel with CircleCI
&lt;/h2&gt;

&lt;p&gt;Before exploring parallel testing with CircleCI, it’s important to place a quick note on why it’s important to run parallel tests on real browsers and devices. &lt;/p&gt;

&lt;p&gt;While it may seem easier to download and test on &lt;a href="https://www.browserstack.com/emulators-simulators"&gt;emulators and simulators&lt;/a&gt;, they are riddled with inadequacies that prevent them from providing a reliable test environment. For example, they cannot mimic low network conditions, low battery, or incoming calls. In general, they cannot replicate all features of real browsers and devices, making the results of tests run on them prone to serious error. &lt;/p&gt;

&lt;p&gt;Now, on to CircleCI. &lt;/p&gt;

&lt;p&gt;CircleCI provides us with capabilities to run tests in parallel and achieve faster completion.&lt;/p&gt;

&lt;p&gt;When you run your tests with CircleCI, they usually run on a single VM. Now, the more tests, the more time it will take to complete on one machine. In order to reduce this time, you can run tests in parallel by distributing them across multiple separate executors. &lt;/p&gt;

&lt;p&gt;In order to do this, you need to specify the parallelism level to define how many separate executors should be spun up for your job. After that, for separating the test files, you can either use CircleCI CLI or environment variables to configure each machine individually.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to set up parallelism in CircleCI
&lt;/h2&gt;

&lt;p&gt;Test suites are usually defined at the job level in your .circleci/config.yml file. So let’s first set up the parallelism level on your config file. &lt;/p&gt;

&lt;p&gt;This parallelism key defines how many independent executors CircleCI will create to run your tests. To do this, you just need to add this key before calling the steps to run your tests. &lt;/p&gt;

&lt;p&gt;Depending on your CircleCI’s pricing plan, the parallelism value can be increased to match your requirements.&lt;/p&gt;

&lt;p&gt;To run a job’s steps in parallel, &lt;strong&gt;set the parallelism key to a value greater than 1&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ~/.circleci/config.yml

version: 2

jobs:

  test:

    docker:

      - image: cimg/&amp;lt;language&amp;gt;:&amp;lt;version TAG&amp;gt;

        auth:

          username: yourdockerhub-user

          password: $DOCKERHUB_PASSWORD  

    parallelism: 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, in order to split the actual tests, the next step is to use the CircleCI CLI (Command Line Interface) to call additional commands to split the tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to split test files using CircleCI CLI
&lt;/h2&gt;

&lt;p&gt;CircleCI supports automatic test allocation across your containers. The allocation is based on filename or class name, depending on the requirements of the test-runner we are using. It requires the CircleCI CLI, which is automatically injected into your build at run-time.&lt;/p&gt;

&lt;p&gt;The commands that we will use for splitting the test files are glob and split. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A glob is basically a pattern that will match a list of filenames to a specific pattern that you specify.&lt;/li&gt;
&lt;li&gt;The split command, by default, will split your tests according to a list of filenames, but you can also use other strategies such as splitting it by timing data or file size.
By using these two commands, you can split your tests into multiple executors that are independent of each other as you can see from the image above.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Globbing the tests
&lt;/h2&gt;

&lt;p&gt;In order to assist in defining your test suite, the CircleCI CLI supports globbing test files using the following patterns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;* matches any sequence of characters (excluding path separators)&lt;/li&gt;
&lt;li&gt;** matches any sequence of characters (including path separators)&lt;/li&gt;
&lt;li&gt;? matches any single character (excluding path separators)&lt;/li&gt;
&lt;li&gt;[abc] matches any character (excluding path separators) against characters in brackets&lt;/li&gt;
&lt;li&gt;{foo, bar,…} matches a sequence of characters if any of the alternatives in braces matches
So to glob test files, pass one or more patterns to the CircleCI tests glob command.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let’s look at how we can achieve this in our configuration file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;circleci tests glob "tests/unit/*.java" "tests/functional/*.java"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use the glob command in your config file with the echo command as shown below, to check the results of pattern match:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ~/.circleci/config.yml

version: 2

jobs:

  test:

    docker:

      - image: cimg/&amp;lt;language&amp;gt;:&amp;lt;version TAG&amp;gt;

        auth:

          username: mydockerhub-user

          password: $DOCKERHUB_PASSWORD  # context / project UI env-var reference

    parallelism: 4

    steps:

      - run:

          command: |

            echo $(circleci tests glob "foo/**/*" "bar/**/*")

            circleci tests glob "foo/**/*" "bar/**/*" | xargs -n 1 echo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Splitting the tests
&lt;/h2&gt;

&lt;p&gt;The split command, by default, will split your tests according to a list of filenames but you can also use other strategies such as splitting it by timing data or file size. Let’s discuss all of the splitting techniques.&lt;/p&gt;

&lt;h2&gt;
  
  
  Split By Name
&lt;/h2&gt;

&lt;p&gt;This is the default splitting technique. So in case you don’t specify a method using the –split-by flag, CircleCI expects a list of filenames/classnames and splits them alphabetically by test name. &lt;/p&gt;

&lt;p&gt;There are a few ways to provide this list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a text file with test filenames
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;circleci tests split test_filenames.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Provide a path to the test files
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;circleci tests split &amp;lt; /path/to/items/to/split
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Pipe a glob of test files
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;circleci tests glob "test/**/*.java" | circleci tests split
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the list of names has been provided, CLI looks up the number of available containers, along with the current container index, and then it uses the deterministic splitting algorithms to split the test files across all available containers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Split By Time
&lt;/h2&gt;

&lt;p&gt;This is the best way to optimize your test suite across a set of parallel executors. This ensures that the tests are split in the evenest way, leading to overall reduced test time.&lt;/p&gt;

&lt;p&gt;In order to split by test timings, use the –split-by flag with the timings split type. The available timings data will then be analyzed and your tests will be split across the parallel-running containers as evenly as possible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;circleci tests glob "**/*.go" | circleci tests split --split-by=timings
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On each successful run of a test suite, the timings data is saved from the directory specified by the path in the &lt;a href="https://circleci.com/docs/2.0/configuration-reference/#store_test_results"&gt;store_test_results &lt;/a&gt;step. This timings data mentions how long each test took to complete per filename or classname, depending on the language used.&lt;/p&gt;

&lt;p&gt;One thing to be considered is if you do not use &lt;strong&gt;store_test_results&lt;/strong&gt;, there will be no timing data available for splitting your tests.&lt;/p&gt;

&lt;p&gt;The CLI expects both filenames and classnames to be present in the timing data produced by the test suite. By default, splitting defaults to the filename, but you can specify classnames by using the &lt;strong&gt;–timings-type&lt;/strong&gt; flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat my_java_test_classnames | circleci tests split --split-by=timings --timings-type=classname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For partially found test results, we automatically assign a random small value to any test we did not find timing data for. You can override this assigned value to a specific value with the &lt;strong&gt;–time-default&lt;/strong&gt; flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;circleci tests glob "**/*.rb" | circleci tests split --split-by=timings --time-default=10s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, If you need to manually store and retrieve timing data, use the &lt;a href="https://circleci.com/docs/2.0/configuration-reference/#store_artifacts"&gt;store_artifacts &lt;/a&gt;step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Splitting by filesize
&lt;/h2&gt;

&lt;p&gt;You can also split tests by filesize. To do this, use the –split-by flag with the filesize split type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;circleci tests glob “**/*.go” | circleci tests split –split-by=filesize
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to split tests using environment variables
&lt;/h2&gt;

&lt;p&gt;CircleCI provides us with two environment variables that can be used in place of the CLI to configure each container individually. &lt;/p&gt;

&lt;p&gt;They are &lt;strong&gt;CIRCLE_NODE_TOTAL **and **CIRCLE_NODE_INDEX&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;**CIRCLE_NODE_TOTAL **is the total number of parallel containers being used to run your job. &lt;br&gt;
**CIRCLE_NODE_INDEX **is the index of the specific container that is currently running. The environment variables ensure us full control over parallelism.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to run split tests
&lt;/h2&gt;

&lt;p&gt;Now after globbing and splitting the tests, it’s time to run them. To combine test grouping with test execution, you can consider saving the grouped tests to a file and then passing this file to your test runner.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;circleci tests glob "test/**/*.rb" | circleci tests split &amp;gt; /tmp/tests-to-run

bundle exec rspec $(cat /tmp/tests-to-run)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The contents of the file /tmp/tests-to-run will be different in each container, based on &lt;strong&gt;$CIRCLE_NODE_INDEX&lt;/strong&gt; and &lt;strong&gt;$CIRCLE_NODE_TOTAL&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Applying test parallelism using CircleCI regardless of your underlying technical approach is always beneficial because it will speed up your overall execution time and in some cases, can even reduce the time by half. &lt;/p&gt;

&lt;p&gt;Utilize the steps in this article to run parallel tests in CircleCI, thus getting faster results and integrating speed into your CI/CD pipeline with ease. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to run integration tests on Flutter apps</title>
      <dc:creator>TheNerdyGeek</dc:creator>
      <pubDate>Mon, 07 Mar 2022 05:26:21 +0000</pubDate>
      <link>https://dev.to/thenerdygeek/how-to-run-integration-tests-on-flutter-apps-dcp</link>
      <guid>https://dev.to/thenerdygeek/how-to-run-integration-tests-on-flutter-apps-dcp</guid>
      <description>&lt;p&gt;Flutter, designed by Google, is a free and open-source framework for building visually appealing, natively compiled, and multi-platform applications from a single codebase.&lt;/p&gt;

&lt;p&gt;Flutter has become quite popular due to its ability to create multi-platform apps. It enables users to build, deploy and test web, mobile, desktop, and embedded applications from a single codebase.&lt;/p&gt;

&lt;p&gt;In this article, let’s explore how to run integration tests on Flutter apps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction To Flutter &lt;/li&gt;
&lt;li&gt;Features of Flutter Framework&lt;/li&gt;
&lt;li&gt;Testing In Flutter Apps&lt;/li&gt;
&lt;li&gt;Integration Testing In Flutter Apps&lt;/li&gt;
&lt;li&gt;Migrating From Flutter Driver&lt;/li&gt;
&lt;li&gt;Integration_Test Package&lt;/li&gt;
&lt;li&gt;Steps To Perform Integration Testing In Flutter Apps&lt;/li&gt;
&lt;li&gt;Integration Tests In Flutter Apps With BrowserStack &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Introduction To Flutter
&lt;/h2&gt;

&lt;p&gt;Flutter is an open-source mobile UI framework that can create Android and iOS apps (among other platforms) from a single codebase.&lt;/p&gt;

&lt;p&gt;Generally, frameworks offer different features to develop mobile applications. For example, Android provides a framework based on Java and Kotlin to develop mobile apps, whereas iOS uses a framework based on Objective-C or Swift language.&lt;/p&gt;

&lt;p&gt;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 resources, time, and effort.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features of Flutter Framework
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Facilitates fast development&lt;/li&gt;
&lt;li&gt;Multi-Platform support&lt;/li&gt;
&lt;li&gt;Provides a modern and reactive framework&lt;/li&gt;
&lt;li&gt;Uses the easy to learn Dart programming language&lt;/li&gt;
&lt;li&gt;Fluid and intuitive user interfaces&lt;/li&gt;
&lt;li&gt;Vast widget catalog&lt;/li&gt;
&lt;li&gt;Runs the same UI for multiple platforms&lt;/li&gt;
&lt;li&gt;Stable and Reliable&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Testing In Flutter Apps
&lt;/h2&gt;

&lt;p&gt;Flutter supports three types of tests:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Unit Test&lt;/li&gt;
&lt;li&gt;Widget Test&lt;/li&gt;
&lt;li&gt;Integration Test&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;A unit test verifies the behavior of a method or class.&lt;/li&gt;
&lt;li&gt;A widget test checks the behavior of Flutter widgets without having to run the app.&lt;/li&gt;
&lt;li&gt;An integration test (also called end-to-end testing or GUI testing) runs the entire application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Integration Testing In Flutter Apps
&lt;/h2&gt;

&lt;p&gt;Unit tests and Widget tests can test individual classes, widgets, or functions. However, they don’t verify how individual components work together or monitor application performance on real devices. This is where integration tests come in. &lt;/p&gt;

&lt;p&gt;Integration tests in Flutter are written using the integration test package, provided by the SDK. This is Flutter’s version of Selenium WebDriver (generic web), Protractor (Angular), Espresso (Android), or Earl Gray (iOS). The package internally uses flutter driver to drive the test on a device.&lt;/p&gt;

&lt;p&gt;Tests written with the integration_test package can:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run directly on the target device, enabling tests on numerous Android or iOS devices.&lt;/li&gt;
&lt;li&gt;Run using flutter test integration_test.&lt;/li&gt;
&lt;li&gt;Use flutter_test APIs, which makes the creation of integration tests similar to creating widget tests.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Migrating From Flutter Driver
&lt;/h2&gt;

&lt;p&gt;When Flutter was introduced, integration tests were written using flutter_driver, which enabled testers to maintain programmatic control of a Flutter app. On running the futter drive command, it initiates 2 processes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A “driver” process on the host machine (i.e. the developer’s laptop) that sends instructions to and receives data from the app.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The app is configured to identify connections coming from the driver process.&lt;br&gt;
This allowed the developer to write tests in plain Dart that could interact with the app. However, it came with significant disadvantages:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The driver code couldn’t share any code with the app or unit tests. In fact, it couldn’t leverage any package: flutter dependencies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It relied on strongly-typed APIs because it could not import Key, Widget, or MyCustomWidget. find.byType(‘EvnetsPage’) was often mistyped and misread.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Integration_Test Package
&lt;/h2&gt;

&lt;p&gt;The integration_test package was released to fix some of the issues mentioned above. Here, the code for tests runs in the same isolate as the app code itself. In other words, it can access the same memory. This essentially resolves the previous issues, and offers a few other benefits:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Same API as component tests.&lt;/li&gt;
&lt;li&gt;Can share code with the app.&lt;/li&gt;
&lt;li&gt;Internal app state is totally visible to tests, and runApp is called inside the test.&lt;/li&gt;
&lt;li&gt;Since tests are built into the app executable, they can now run on physical devices.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Steps To Perform Integration Testing In Flutter Apps
&lt;/h2&gt;

&lt;p&gt;This example will demonstrate how to test a counter app. This demonstrates how to set up integration tests, how to verify if a specific text is being displayed by the app, how to tap specific widgets, and how to run integration tests.&lt;/p&gt;

&lt;p&gt;In order to perform the Integration test, follow the below steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an app to test.&lt;/li&gt;
&lt;li&gt;Add the integration_test dependency.&lt;/li&gt;
&lt;li&gt;Create the test files.&lt;/li&gt;
&lt;li&gt;Write the integration test.&lt;/li&gt;
&lt;li&gt;Run the integration test.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Create an app to test
&lt;/h2&gt;

&lt;p&gt;First, create an app for testing. This test will use a counter app produced by the flutter create command. This app will let a user tap on a button to increase one count.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';

void main() =&amp;gt; runApp(const MyApp());

class MyApp extends StatelessWidget {

  const MyApp({Key? key}) : super(key: key);

  @override

  Widget 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

  _MyHomePageState createState() =&amp;gt; _MyHomePageState();

}

class _MyHomePageState extends State&amp;lt;MyHomePage&amp;gt; {

  int _counter = 0;

  void _incrementCounter() {

    setState(() {

      _counter++;

    });

  }

  @override

  Widget build(BuildContext context) {

    return Scaffold(

      appBar: AppBar(

        title: Text(widget.title),

      ),

      body: Center(

        child: Column(

          mainAxisAlignment: MainAxisAlignment.center,

          children: &amp;lt;Widget&amp;gt;[

            const Text(

              'You have pushed 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 reading the text.

              key: const Key('counter'),

              style: Theme.of(context).textTheme.headline4,

            ),

          ],

        ),

      ),

      floatingActionButton: FloatingActionButton(

        // Provide a Key to this button. This allows finding this

        // specific button inside the test suite, and tapping it.

        key: const Key('increment'),

        onPressed: _incrementCounter,

        tooltip: 'Increment',

        child: const Icon(Icons.add),

      ),

    );

  }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://flutter.cn/docs/cookbook/testing/integration/introduction"&gt;Source&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Add the integration_test dependency
&lt;/h2&gt;

&lt;p&gt;Now, use the &lt;strong&gt;integration_test&lt;/strong&gt;, &lt;strong&gt;flutter_driver&lt;/strong&gt;, and **flutter_test **packages for writing integration tests.&lt;/p&gt;

&lt;p&gt;Add these dependencies to the dev_dependencies section of the app’s pubspec.yaml file. The location of the package should be the Flutter SDK.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# pubspec.yaml

dev_dependencies:

  integration_test:

    sdk: flutter

  flutter_test:

    sdk: flutter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create the test files
&lt;/h2&gt;

&lt;p&gt;Create a new directory, integration_test, with an empty app_test.dart file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;counter_app/

  lib/

    main.dart

  integration_test/

    app_test.dart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://docs.flutter.dev/cookbook/testing/integration/introduction"&gt;Source&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Write the integration test
&lt;/h2&gt;

&lt;p&gt;Now, write the integration test with the steps below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initialize IntegrationTestWidgetsFlutterBinding, a singleton service that runs tests on a physical device.&lt;/li&gt;
&lt;li&gt;Interact and test widgets via the WidgetTester class.&lt;/li&gt;
&lt;li&gt;Test the necessary scenarios.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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 test', () {

    testWidgets('tap on the floating action button, 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 action button.

      await tester.tap(fab);

      // Triggers a frame.

      await tester.pumpAndSettle();

      // Verifies if the counter increments by 1.

      expect(find.text('1'), findsOneWidget);

    });

  });

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://docs.flutter.dev/cookbook/testing/integration/introduction"&gt;Source&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Run the integration test
&lt;/h2&gt;

&lt;p&gt;The process of executing integration tests depends greatly on the platform used. If the platform so permits, You can test on mobile devices or web browsers.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Mobile&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To test on a real iOS / Android device, first, connect the device and run the following command from the root of the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flutter test integration_test/app_test.dart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or, specify the directory to run all integration tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flutter test integration_test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command runs the app and integration tests on the target device.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Web&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To test on a web browser (Chrome, in this example), &lt;a href="https://chromedriver.chromium.org/downloads"&gt;Download ChromeDriver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Next, create a new directory named test_driver containing a new file named integration_test.dart:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:integration_test/integration_test_driver.dart';

Future&amp;lt;void&amp;gt; main() =&amp;gt; integrationDriver();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Launch WebDriver, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chromedriver --port=4444
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the root of the project, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flutter drive \

  --driver=test_driver/integration_test.dart \

  --target=integration_test/app_test.dart \

  -d web-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://docs.flutter.dev/cookbook/testing/integration/introduction"&gt;Source&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
