-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Setup
I have a Domain test which is agnostic to robo electric and is actually in a separate gradle module with no dependencies
abstract class DomainTest {
@Nested
inner class CaseSpecificTest {
@Test
fun test() {}
}
}
I then have another gradle module for android that implements the domain
@ExtendWith(RoboElectricTest)
AndroidSpecficImpDomainTest : DomainTest {}
Cannot put RoboElectricTest annotation on Domain test without breaking decoupling
Issue
This code is failing on the nested tests
JUnit5RobolectricTestRunnerHelper
...
require(testClass.isExtendedWithRobolectric()) {
"Test class ${testClass.name} is not extended with ${RobolectricExtension::class.simpleName}"
}
I think its because isExtendedWithRobolectric
only checks for the declaringClass
but does not also check for the super class
internal fun Class<*>.isExtendedWithRobolectric(): Boolean {
val isExtended = findAnnotations(ExtendWith::class.java).any { annotation ->
val valueMethod = annotation.javaClass.getDeclaredMethod("value")
@Suppress("UNCHECKED_CAST")
val value: Array<Class<*>> = valueMethod.invoke(annotation) as Array<Class<*>>
value.any { it.name == RobolectricExtension::class.java.name }
}
return if (isExtended) {
true
} else if (declaringClass != null) {
declaringClass.isExtendedWithRobolectric()
#### Maybe could add some thing like this ####
} else if (superClass != null) {
superClass.isExtendedWithRoboelectric()
} else {
false
}
}
Metadata
Metadata
Assignees
Labels
No labels