title: How to Unit Test a Room Dao Query that Returns a PagingSource From Paging 3
body: <p>My question is actually quite generic. I want to know how to unit test a <strong>Room</strong> <strong>Dao</strong> query that returns a <strong>PagingSource</strong> From <strong>Paging 3</strong>.</p>
  <p>I have a <strong>Room</strong> <strong>Dao</strong> query:</p>
  <pre><code>    @Query(&quot;SELECT * FROM database&quot;)
      fun getChocolateListData(): PagingSource&lt;Int, Chocolate&gt;
  </code></pre>
  <p>I'm wondering how this query can be unit tested.</p>
  <p>What I've tried so far (using in-memory <strong>Room</strong> database for testing):</p>
  <pre><code>@FlowPreview
  @Test
  fun saveChocolateToDbSavesData() = runBlocking {
      val dao: Dao by inject()
  
      val chocolate = Chocolate(
          name = &quot;Dove&quot;
      )
      dao.saveChocolate(chocolate) 
  
      val pagingSourceFactory = { dao.getChocolateListData() }
      val pagingDataFlow: Flow&lt;PagingData&lt;Chocolate&gt;&gt; = Pager(
          config = PagingConfig(
              pageSize = 50,
              maxSize = 200,
              enablePlaceholders = false
          ),
          pagingSourceFactory = pagingSourceFactory
      ).flow
  
      val chocolateListFlow = pagingDataFlow.testIn(coroutinesTestRule)
      Assert.assertEquals(PagingData.from(listOf(chocolate)), chocolateListFlow.emissions[0])
  }
  </code></pre>
  <p>This doesn't pass, however:</p>
  <blockquote>
  <p>junit.framework.AssertionFailedError:   Expected
  :androidx.paging.PagingData@7d6c23a1  Actual
  :androidx.paging.PagingData@321123d2</p>
  </blockquote>
  <p>Not sure how to get it right. Any help would be greatly appreciated!</p>