title: Exception in thread "main @coroutine#2" java.lang.NullPointerException in ViewModelTest?
body: <p>I have wrote unit testing in ViewModel with coroutines with mockito. class but I am getting following exception</p>
  <pre><code> Exception in thread &quot;main @coroutine#2&quot; java.lang.NullPointerException
      at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModel$getGifsFromText$1.invokeSuspend(GiphyTaskViewModel.kt:24)
      at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
      at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
      at kotlinx.coroutines.test.TestCoroutineDispatcher.dispatch(TestCoroutineDispatcher.kt:50)
      at kotlinx.coroutines.test.internal.TestMainDispatcher.dispatch(MainTestDispatcher.kt:35)
      at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:305)
      at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
      at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:27)
      at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
      at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:158)
      at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
      at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
      at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:49)
      at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source)
      at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModel.getGifsFromText(GiphyTaskViewModel.kt:22)
      at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest$onCreation_fetchUserApiCalled_dataSavedToLiveData$1.invokeSuspend(GiphyTaskViewModelTest.kt:61)
      at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
      at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
      at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
      at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:84)
      at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
      at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
      at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
      at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
      at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest.onCreation_fetchUserApiCalled_dataSavedToLiveData(GiphyTaskViewModelTest.kt:57)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.mockito.internal.runners.DefaultInternalRunner$1$1.evaluate(DefaultInternalRunner.java:54)
      at com.example.giphyandroidapp.viewmodel.TestCoroutineRule$apply$1.evaluate(TaskCoroutineRule.kt:22)
      at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
      at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
      at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
      at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
      at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
      at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:99)
      at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:105)
      at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:40)
      at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
      at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:42)
      at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80)
      at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:72)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
      at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
      at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
      at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
      at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
      at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
      at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
      at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
      at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
  
  
  java.lang.RuntimeException: Method getMainLooper in android.os.Looper not mocked. See http://g.co/androidstudio/not-mocked for details.
  
      at android.os.Looper.getMainLooper(Looper.java)
      at androidx.arch.core.executor.DefaultTaskExecutor.isMainThread(DefaultTaskExecutor.java:77)
      at androidx.arch.core.executor.ArchTaskExecutor.isMainThread(ArchTaskExecutor.java:116)
      at androidx.lifecycle.LiveData.assertMainThread(LiveData.java:486)
      at androidx.lifecycle.LiveData.observeForever(LiveData.java:224)
      at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest$onCreation_fetchUserApiCalled_dataSavedToLiveData$1.invokeSuspend(GiphyTaskViewModelTest.kt:63)
      at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
      at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
      at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
      at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:84)
      at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
      at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
      at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
      at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
      at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest.onCreation_fetchUserApiCalled_dataSavedToLiveData(GiphyTaskViewModelTest.kt:57)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.mockito.internal.runners.DefaultInternalRunner$1$1.evaluate(DefaultInternalRunner.java:54)
      at com.example.giphyandroidapp.viewmodel.TestCoroutineRule$apply$1.evaluate(TaskCoroutineRule.kt:22)
      at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
      at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
      at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
      at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
      at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
      at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:99)
      at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:105)
      at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:40)
      at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
      at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:42)
      at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80)
      at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:72)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
      at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
      at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
      at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
      at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
      at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
      at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
      at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
      at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
  </code></pre>
  <p>below my ViewModel class where I have implemented viewmodel logic</p>
  <pre><code> @HiltViewModel
  class GiphyTaskViewModel
  @Inject
  constructor(private val giphyTaskRepository: GiphyTaskRepository):ViewModel()
  {
      var giphyresponse = MutableLiveData&lt;Result&lt;List&lt;DataItem&gt;?&gt;&gt;()
  
  
  
      fun getGifsFromText(apikey:String,text:String,limit:Int)= viewModelScope.launch {
          giphyTaskRepository.getGifsFromText(apikey,text,limit).let { response-&gt;
              if(response?.isSuccessful){
                  var list=response.body()?.data
                  giphyresponse.postValue(Success(list))
              }else{
                  Error(Exception(response.message()))
  
              }
  
          }
      }
  
  }
  </code></pre>
  <p>below Repository  class</p>
  <pre><code>class GiphyTaskRepository
  @Inject
  constructor(private val giphyTaskApiService: GiphyTaskApiService)
  {
  
      suspend fun getGifsFromText(apikey:String,text:String,limit:Int)=
          giphyTaskApiService.getGifsFromText(apikey,text,limit)
  }
  </code></pre>
  <p>below interface class</p>
  <p>interface GiphyTaskApiService {</p>
  <pre><code>    @GET(&quot;gifs/search&quot;)
      suspend fun getGifsFromText(
          @Query(&quot;api_key&quot;) api_key:String,
          @Query(&quot;q&quot;) q:String ,
          @Query(&quot;limit&quot;) limit:Int
      ):Response&lt;GiphyResponse&gt;
  }
  </code></pre>
  <p>below my ViewModel test class</p>
  <pre><code> @ExperimentalCoroutinesApi
  @RunWith(MockitoJUnitRunner::class)
  class GiphyTaskViewModelTest {
  
  
  
  
  
  
  
      @Mock
      private lateinit var apiUsersObserver: Observer&lt;Result&lt;List&lt;DataItem&gt;?&gt;&gt;
  
  
      @RegisterExtension
      @JvmField
      @get:Rule
      val testInstantTaskExecutorRule: TestRule = InstantTaskExecutorRule()
  
      @get:Rule
     val testCoroutineRule = TestCoroutineRule()
      @Mock
       var giphyTaskViewModel:GiphyTaskViewModel? = null
  
      @Mock
       lateinit var  giphyTaskRepository:GiphyTaskRepository
  
  
  
  
  
  
  
  
      @Before
       fun setUp() {
  
  
          /* Create a mock response */;
          /* Create a mock response */;
  
  
                  giphyTaskViewModel = GiphyTaskViewModel(giphyTaskRepository)
          }
  
      @Test
      fun onCreation_fetchUserApiCalled_dataSavedToLiveData() {
          runBlockingTest {
  
  
  
              val response: Response&lt;GiphyResponse&gt; = mock()
  
  
              giphyTaskViewModel?.getGifsFromText(Constants.Api_Key,&quot;text&quot;, Constants.Limit)
             `when`(giphyTaskRepository.getGifsFromText(Constants.Api_Key,&quot;text&quot;, Constants.Limit)).thenReturn(response)
              giphyTaskViewModel?.giphyresponse?.observeForever(apiUsersObserver)
              assertNotNull(giphyTaskViewModel?.giphyresponse?.value)
  
  
  
  
          }
      }
  
  
  
  }
  </code></pre>
  <p>What I have tried</p>
  <p>1.[I have tried following link][1]</p>
  <ol start="2">
  <li>I have rewrite Viewmodel logic but I am getting following exception
  xception in thread &quot;main @coroutine#2&quot; java.lang.NullPointerException
  at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModel$getGifsFromText$1.invokeSuspend(GiphyTaskViewModel.kt:26)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
  at kotlinx.coroutines.test.TestCoroutineDispatcher.dispatch(TestCoroutineDispatcher.kt:50)
  at kotlinx.coroutines.test.internal.TestMainDispatcher.dispatch(MainTestDispatcher.kt:35)
  at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:305)
  at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
  at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:27)
  at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
  at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:158)
  at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
  at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
  at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:49)
  at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source)
  at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModel.getGifsFromText(GiphyTaskViewModel.kt:24)
  at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest$onCreation_fetchUserApiCalled_dataSavedToLiveData$1.invokeSuspend(GiphyTaskViewModelTest.kt:82)
  at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest$onCreation_fetchUserApiCalled_dataSavedToLiveData$1.invoke(GiphyTaskViewModelTest.kt)
  at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest$onCreation_fetchUserApiCalled_dataSavedToLiveData$1.invoke(GiphyTaskViewModelTest.kt)
  at kotlinx.coroutines.test.TestBuildersKt$runBlockingTest$deferred$1.invokeSuspend(TestBuilders.kt:50)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
  at kotlinx.coroutines.test.TestCoroutineDispatcher.dispatch(TestCoroutineDispatcher.kt:50)
  at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:305)
  at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
  at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:27)
  at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
  at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:158)
  at kotlinx.coroutines.BuildersKt__Builders_commonKt.async(Builders.common.kt:91)
  at kotlinx.coroutines.BuildersKt.async(Unknown Source)
  at kotlinx.coroutines.BuildersKt__Builders_commonKt.async$default(Builders.common.kt:84)
  at kotlinx.coroutines.BuildersKt.async$default(Unknown Source)
  at kotlinx.coroutines.test.TestBuildersKt.runBlockingTest(TestBuilders.kt:49)
  at kotlinx.coroutines.test.TestBuildersKt.runBlockingTest$default(TestBuilders.kt:45)
  at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest.onCreation_fetchUserApiCalled_dataSavedToLiveData(GiphyTaskViewModelTest.kt:75)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.base/java.lang.reflect.Method.invoke(Method.java:566)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
  at org.mockito.internal.runners.DefaultInternalRunner$1$1.evaluate(DefaultInternalRunner.java:54)
  at com.example.giphyandroidapp.viewmodel.TestCoroutineRule$apply$1.evaluate(TaskCoroutineRule.kt:22)
  at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
  at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
  at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
  at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
  at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
  at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:99)
  at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:105)
  at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:40)
  at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
  at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
  at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
  at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)</li>
  </ol>
  <p>java.lang.NullPointerException
  at androidx.arch.core.executor.DefaultTaskExecutor.isMainThread(DefaultTaskExecutor.java:77)
  at androidx.arch.core.executor.ArchTaskExecutor.isMainThread(ArchTaskExecutor.java:116)
  at androidx.lifecycle.LiveData.assertMainThread(LiveData.java:486)
  at androidx.lifecycle.LiveData.observeForever(LiveData.java:224)
  at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest$onCreation_fetchUserApiCalled_dataSavedToLiveData$1.invokeSuspend(GiphyTaskViewModelTest.kt:84)
  at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest$onCreation_fetchUserApiCalled_dataSavedToLiveData$1.invoke(GiphyTaskViewModelTest.kt)
  at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest$onCreation_fetchUserApiCalled_dataSavedToLiveData$1.invoke(GiphyTaskViewModelTest.kt)
  at kotlinx.coroutines.test.TestBuildersKt$runBlockingTest$deferred$1.invokeSuspend(TestBuilders.kt:50)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
  at kotlinx.coroutines.test.TestCoroutineDispatcher.dispatch(TestCoroutineDispatcher.kt:50)
  at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:305)
  at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
  at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:27)
  at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
  at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:158)
  at kotlinx.coroutines.BuildersKt__Builders_commonKt.async(Builders.common.kt:91)
  at kotlinx.coroutines.BuildersKt.async(Unknown Source)
  at kotlinx.coroutines.BuildersKt__Builders_commonKt.async$default(Builders.common.kt:84)
  at kotlinx.coroutines.BuildersKt.async$default(Unknown Source)
  at kotlinx.coroutines.test.TestBuildersKt.runBlockingTest(TestBuilders.kt:49)
  at kotlinx.coroutines.test.TestBuildersKt.runBlockingTest$default(TestBuilders.kt:45)
  at com.example.giphyandroidapp.viewmodel.GiphyTaskViewModelTest.onCreation_fetchUserApiCalled_dataSavedToLiveData(GiphyTaskViewModelTest.kt:75)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.base/java.lang.reflect.Method.invoke(Method.java:566)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
  at org.mockito.internal.runners.DefaultInternalRunner$1$1.evaluate(DefaultInternalRunner.java:54)
  at com.example.giphyandroidapp.viewmodel.TestCoroutineRule$apply$1.evaluate(TaskCoroutineRule.kt:22)
  at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
  at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
  at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
  at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
  at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
  at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:99)
  at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:105)
  at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:40)
  at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
  at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
  at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
  at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)</p>
  <p>I want to know where exactly I am making mistake what I have to inorder to pass the tests successfully</p>