KV
10/21/2020, 1:29 PMbuildRequestUrl
which build the URL including headers and query parameters.
Now I am working on tests for api call's response.
and I am debugging the code where I build the URL which is this
val uriBuilder = Uri.parse(baseUrl).buildUpon()
But the issue is it throws null pointer exception and result is null (see attached screenshot)
How do I solve this issue?
I am using below library
testImplementation 'junit:junit:4.13'
testImplementation "org.mockito:mockito-core:3.4.6"
testImplementation 'androidx.arch.core:core-testing:2.1.0'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.9'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
I am using below class
@ExperimentalCoroutinesApi
class TestCoroutineRule : TestRule {
private val testCoroutineDispatcher = TestCoroutineDispatcher()
private val testCoroutineScope = TestCoroutineScope(testCoroutineDispatcher)
override fun apply(base: Statement, description: Description?) = object : Statement() {
@Throws(Throwable::class)
override fun evaluate() {
Dispatchers.setMain(testCoroutineDispatcher)
base.evaluate()
Dispatchers.resetMain()
testCoroutineScope.cleanupTestCoroutines()
}
}
fun runBlockingTest(block: suspend TestCoroutineScope.() -> Unit) =
testCoroutineScope.runBlockingTest { block() }
}
I am using the below rule in the test class:
@get:Rule
val testInstantTaskExecutorRule: TestRule = InstantTaskExecutorRule()
@get:Rule
val testCoroutineRule = TestCoroutineRule()