To enable support of mock type generation through KSP in Mockative 3, special consideration had to be made to ensure the least amount of friction when writing tests, while not polluting production builds with generated mock classes. This is achieved through a Gradle plugin that conditionally enables code generation depending on various conditions:
- Code generation is disabled complete if the Gradle property
io.mockative.disabled=trueis included. This is to provide developers with a way to ensure generated code does not end up in production builds, should any of the following steps prevent that.- This is also the only way to disable the application of the
all-openplugin on types annotated with@Mockable.
- This is also the only way to disable the application of the
- Code generation is enabled if one of these conditions are fulfilled:
- The Gradle property
io.mockative.enabled=trueis included. - If a
testorverificationtask is detected. - If a
test[...]UnitTesttask is executed (Android unit tests) - If a
connected[...]AndroidTesttask is detected (Android instrumented tests).
- The Gradle property
Should any of the heuristics mentioned in point 2 not work, please open an issue so we can have a look at supporting that use case.