Cheat sheet

Along the way we learned a few lessons that makes testing easier

  • Create a directory in /src/test/resources/ut/[yourClassName-no extension] where you will store all the test data you want to process. Use KeepTestUtils.getResourceAsJson("file.json",YourTestClass.class) to retrieve values
  • Annotate your class with @UnitTest, @IntegrationTest or @PerformanceTest. The first one runs on mvn package the second on on mvn verify while the last one only runs manual
  • Use the @Mock annotation instead of mock(classname)
  • After the mock definitions, add the Rule using @Rule MockitoRule mockitoRule = MockitoJUnit.rule();
  • Keep this sequence:
  1. Initialize your Mocks in @BeforeEach, using MockitoAnnotations.initMocks(this);
  2. Initialize your local (non mock) variables
  3. Define mock behavior. If you switch 2 and 3, be ready for errors
  • use KeepTestSubscriber[Json] (see Test Helpers)
  • use KeepTestUtils
  • if suitable, extend AbstractDatabaseHandlerTest

Code example

Imports

Variable definitions

BeforeEach