Covering all enum values
Cover Plugin for IntelliJ can write tests which ensure that all possible values of an Enum
type are covered by the test suite, when that Enum
is passed to a method as an argument or is a return value of a method.
With and without "Cover all enum values"
To understand the difference that the Cover all enum values
feature makes to created tests, we can write tests on a simple class which takes an Enum
type as an argument and behaves in different ways depending on that argument's value.
Note in particular that the method exhibits the same behavior when the level
argument is INFORMATIONAL
or WARNING
. Two tests that exercise this method by passing those two values to its first argument will therefore cover the same lines of code.
When we write tests on this method with Cover all enum values
disabled, then Cover Plugin creates these tests:
When we enable Cover all enum values
and write tests again, Cover Plugin creates these tests:
With Cover all enum values
enabled the Cover Plugin creates an extra test, to ensure that both the INFORMATION
and WARNING
levels are tested, even though the extra test may not increase the test suite's measured coverage.
Disable "Cover all enum values"
The Cover all enum values
feature is enabled by default. To disable, go to Diffblue > Change Settings > Test Creation
in IntelliJ, and uncheck the Allow writing tests for all enum values
option.
Last updated