Documentation

Documentation versions (currently viewingVaadin 23)
Check out the new styling guides

Unit Testing in Flow

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

Mocking

JUnit mocks use Mockito. Other mocking libraries should not 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.

Conventions

JUnit tests should not 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 is always good practice to refer to 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>
Tip
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 is applicable to target 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, refer to the IDE documentation.

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

760C992B-3AFF-4F13-8C5A-6BF369C22668