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. UseKeepTestUtils.getResourceAsJson("file.json",YourTestClass.class)
to retrieve values - Annotate your class with
@UnitTest
,@IntegrationTest
or@PerformanceTest
. The first one runs onmvn package
the second on onmvn verify
while the last one only runs manual - Use the
@Mock
annotation instead ofmock(classname)
- After the mock definitions, add the Rule using
@Rule MockitoRule mockitoRule = MockitoJUnit.rule();
- Keep this sequence:
- Initialize your Mocks in
@BeforeEach
, usingMockitoAnnotations.initMocks(this);
- Initialize your local (non mock) variables
- 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