Documentation versions (currently viewingVaadin 23)

You are viewing documentation for Vaadin 23. View latest documentation

Unit Testing in Flow

Every change in the code base requires a JUnit test for the code change. In cases where a JUnit test isn’t practicable, an Integration Test should be added instead.


JUnit mocks use Mockito. Other mocking libraries shouldn’t be used, as they may break when there are version updates. No new mocking libraries should be added to the project.

To help with tests, there are many Mock* classes for use that make the setup for testing simpler.


JUnit tests shouldn’t leak settings and changes outside the test execution. This means that any changes to current instances and system properties should be reset after the test execution.

Test method naming must follow the convention: {given}_{when}_{then}; for example:

void setValue_sameValue_firesNoEvent()
void setValue_differentValue_firesOneEvent()

It’s always good practice to see existing tests as an example of how to write new tests.

How to Run the Tests

Issuing the following command results in running all the tests in the specified module:

mvn test -pl <module-name>
Tests in nested modules
The above command template works only for direct child modules of the directory. To run tests in nested modules, use the syntax :<module-name>, for example, mvn test -pl :flow-maven-plugin. Or use the full path instead: mvn test -pl flow-plugins/flow-maven-plugin. The same rule applies when targeting a specific nested module, as in the commands that follow.

To execute tests for a single class, use the following command:

mvn -Dtest=<test-class-name> test -pl <module-folder-name>

Also, to run a single test inside a class:

mvn -Dtest=<test-class-name>#<test-method-name> test -pl <module-folder-name>

To run all the unit tests in the project:

mvn test -am -pl flow

To run tests via your IDE, see the IDE documentation.

Chrome WebDriver is required
Running the unit tests in the flow-client module needs a Chrome WebDriver to be available on your environment, and its version should be configured in flow-client/intern.json. For more information on setting up the WebDriver, see Installing WebDrivers.