> Markdown version of [Integration Testing in Flow](https://vaadin.com/docs/v23/contributing/flow-integration-testing). Section index: [llms.txt](https://vaadin.com/docs/v23/contributing/llms.txt)

# Integration Testing in Flow

Sometimes creating [unit tests](https://vaadin.com/docs/v23/contributing/flow-unit-testing.md) isn’t enough. It might be important to test that the given functionality works end-to-end in an application. This is specially important for features and bugs that depend on the browser functionality. Integration testing in Flow is being done with a View & Integration Test combination.

The integration tests are in [flow-tests](https://github.com/vaadin/flow/tree/master/flow-tests) module. Most of the integration tests for the core part are under `flow-test-core` module. Descriptions about integration test modules are inside [the README.md file in /flow-tests](https://github.com/vaadin/flow/blob/master/flow-tests/README.md).

The integration tests use [TestBench](https://vaadin.com/testbench), for information see [Vaadin TestBench](https://vaadin.com/docs/v23/testing.md). TestBench is a commercial tool, but you need the license for it to only run the tests locally. It’s possible to get a free license to the TestBench product if you contribute to the Vaadin projects frequently.

<!-- vale Vaadin.We = NO -->

You can contact us via our [contact e-mail](mailto:contact@vaadin.com) if you feel you deserve the license - we’re happy to give it to contributors.

<!-- vale Vaadin.We = YES -->

## <a id="creating-the-view-class"></a>Creating the View Class

First you should start by looking if there is already a suitable test view that you can reuse. One way to do it’s by seeing if the code related to the test is being called from any of the existing test views.

The view `@Route` value should be the fully qualified name of the view class like `com.vaadin.flow.uitest.ui.YourTestClassNameView`. For example:

Example of a test view

```java
@Route(value = "com.vaadin.flow.uitest.ui.CompositeView", layout = ViewTestLayout.class)
public class CompositeView extends AbstractDivView {
    // ...
}
```

> **Note:** View class should only depend on Flow HTML components (see components in `com.vaadin.flow.component.html`), like such `NativeButton`, `Div` etc.

### <a id="opening-the-view-class-in-the-browser"></a>Opening the View Class in the Browser

You can open the test view in the browser by first starting up the jetty server for that module. You can trigger the `jetty:run` Maven task for the module through your IDE, or by running the command `mvn jetty:run -pl <test-module-name>` like `mvn jetty:run -pl flow-test-core`.

You can then open the view in the browser for example from *<http://localhost:8888/view/com.vaadin.flow.uitest.ui.CompositeView>* (depending on the route used).

## <a id="creating-the-integration-test-class"></a>Creating the Integration Test Class

The integration test class should be named the same as the `View` class that it tests. For example, `PageView` gets the test class `PageIT`. This enables the `open()` method to find the correct test view path automatically.

The integration test class should extend `ChromeBrowserTest`. Some test classes extend an `Abstract*` class that provides common functionality to be reused in the tests.

Example of a integration test class

```java
public class CompositeIT extends ChromeBrowserTest {
    @Test
    public void changeOnClient() {
        open();
        // ...
    }
}
```

When writing a lot of integration tests, you should use the *Page Object* pattern where the interaction between the browser is handled through an API that’s reused for all the tests. You can read more about it from the [TestBench documentation](https://vaadin.com/docs/v23/testing/browser-based/maintainable-tests-using-page-objects.md).

> **Note:** If the test class contains or modifies some shared objects which can’t be run in parallel, the `@NotThreadSafe` annotation should be present on the class.

## <a id="running-the-integration-tests"></a>Running the Integration Tests

Running all the integration tests takes a while, so it’s more efficient to only compile the modules that changed, and then run the specific ITs written for the changes. **Before running integration tests locally**, install the following modules `mvn install -pl flow-test-util -pl flow-tests/test-resources -pl flow-tests/test-common`.

Running all integration tests for a single module `mvn verify -pl <test-module-folder-name>`. Running all the integration tests `mvn verify -pl flow-tests`.

You can execute tests for single class by running the `mvn -Dit.test=<it-test-class-name> verify -pl <module-folder-name>`. Also, for running a single inside a class you can execute `mvn -Dit.test=<test-class-name>#<test-method-name> test -pl <module-folder-name>`.

To reduce the chance your IT test is flaky, run it several times before publishing it out.

> **Note:** To run the integration tests locally, you should have the Chrome WebDriver installed and configured, as described in [Installing WebDrivers](https://vaadin.com/docs/v23/testing/browser-based/installing-webdrivers.md)

`042EA042-08C3-4A6A-ABEE-49CA76BEE12A`
