test method naming convention(
source-code-method-RESULT-WHEN condition
)need to cover the red and yellow lines displayed in sonarqube
We need to carefully set the conditions to ensure the bottom code is actually tested
in case writing unit tests, we don’t need to annotate with
@MicronautTest
, because we don't need a container env, and it's slowerin case writing component test, we need
@MicronautTest
in the method block, we can add comments
//given, //when, //then
top of the code block, and add proper blank lines to make our code clearer to readif we want to see if one line has been covered by a newly added test, we’ll need to debug the test and add breakpoint in the line, if it stops on the breakpoint, we know that it’s covered.
about the boundary, we need to write unit tests for all the service layer code, not for the controller and Kafka listener;
we need to write component tests for all the controller layer and Kafka listener and producer.