I have found other similar questions but none of the answers were useful. In a method I have something similar to:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// use API available only on Q
} else { ... }
When writing the unit test I would like to be able to check all the conditions.
I have found people saying that I should wrap the check Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
in an object that I can then mock.
If I do that Android Studio shows me a warning because I'm using an API that is for Q+
Other people say that I should use Mockk that allows you to mock static method. The problem is that Build.VERSION.SDK_INT
does not call a method but just a field and I did not find the way to mock it.
Is there a way to do it?
PS I'm using Kotlin