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 plausible then an Integration Test should be added instead.

Mocking

JUnit mocks use Mockito and 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 a good practice to refer to existing tests as an example to how to write new tests.

How to Run the Tests

Running all the tests mvn verify -pl <module-name> would run all the tests in the specified module.

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

For running all the unit tests in the project, you can execute mvn test -am -pl flow.

For running tests through your IDE, please refer to the documentation of your desired IDE.