on your test class, you need to annotate with @Config with an array of sdk as a parameter.
@Config(sdk = {Build.VERSION_CODES.O_MR1})
class SampleTest {}
for Kotlin
@Config(sdk = [Build.VERSION_CODES.O_MR1])
class SampleTest {}
Your tests should run.