You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
abstract class Parent(dependencies: List<Parent>) {
val dependencyFlows = dependencies.map(Parent::flow)
val flow = MutableStateFlow(0)
// get() = field //uncomment this line to fix the test
}
class Child1(child2: Child2) : Parent(listOf(child2)) {
}
class Child2() : Parent(emptyList()) {
}
class Tests {
@Test
fun test() {
//Given
val child2Flow = MutableStateFlow(5)
val child2 = mockk<Child2> {
every { flow } returns child2Flow
}
//When
val child1 = Child1(child2)
//Then
assert(child1.dependencyFlows == listOf(child2Flow))
}
}
Explanation
When you call child2.flow in the test it will return you child2Flow value.
But when Parent accesses flow it does it directly, without calling the property getter, and null is returned.
When even the empty getter is specified Parent starts accessing flow with specified getter, which is properly mockked with MockK
The text was updated successfully, but these errors were encountered:
Code to reproduce the issue
Explanation
When you call
child2.flow
in the test it will return youchild2Flow
value.But when
Parent
accessesflow
it does it directly, without calling the property getter, and null is returned.When even the empty getter is specified
Parent
starts accessingflow
with specified getter, which is properly mockked withMockK
The text was updated successfully, but these errors were encountered: