Hey i am doing testing this function ```internal f...
# mockk
v
Hey i am doing testing this function
Copy code
internal fun graphView(viewGroup: ViewGroup, orientation: graphOrientaion = GraphOrientaion.HORIZONTAL): View {
    return when (orientation) {
        GraphOrientaion.HORIZONTAL -> {
            LayoutInflater.from(viewGroup.context).inflate(R.layout.horizaontal_layout, viewGroup, false)
        }
        GraphOrientaion.VERTICAL -> {
            LayoutInflater.from(viewGroup.context).inflate(R.layout.vertical_layout, viewGroup, false)
        }
    }
}
i added this test cases
Copy code
@Test
fun `graphView - HORIZONTAL view`() {
    val mockOrientation = GraphOrientaion.HORIZONTAL
    every {
        LayoutInflater.from(mockContext).inflate(
            R.layout.horizaontal_layout,
            mockViewGroup,
            false
        )
    } returns mockView
    // EXECUTION
    val view = graphView(mockViewGroup, mockOrientation)
    // VERIFICATION
    assertEquals(mockView, view)
}
what i am doing wrong
java.lang.NullPointerException
at com.vivek$graphView - HORIZONTAL view$1.invoke(TestClass.kt:306)
at com.vivek$graphView - HORIZONTAL view$1.invoke(TestClass.kt:31)
s
Check the lines mentioned in the stacktrace. And Try debugging.
My guess is
viewGroup.context
is null/not set in the
mockViewGroup
v
viewGroup.context
is not null because it working in another test
e
unless you're using Robolectric (which has other issues with mockk), LayoutInflater.from will act like all other Android APIs and either throw or return null, depending on test configuration
v
i am not using Robolectric
r
Bro, it's ui testing not unit testing