-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add base dao test for reduce boilerplate for testing DAOs
- Loading branch information
1 parent
6cb2e19
commit bd3c330
Showing
3 changed files
with
30 additions
and
18 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
app/src/androidTest/java/com/akshay/newsapp/core/utils/DaoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.akshay.newsapp.core.utils | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import androidx.test.core.app.ApplicationProvider | ||
import org.junit.After | ||
import org.junit.Before | ||
|
||
/** | ||
* Base class to reduce boilerplate code for testing DAO(s) of [RoomDatabase]. | ||
*/ | ||
abstract class DaoTest<Database: RoomDatabase>( | ||
private val database: Class<Database> | ||
): MockitoTest() { | ||
|
||
protected lateinit var db: Database | ||
|
||
@Before | ||
override fun setup() { | ||
super.setup() | ||
db = Room.inMemoryDatabaseBuilder(ApplicationProvider.getApplicationContext<Context>(), database).build() | ||
} | ||
|
||
@After | ||
fun teardown() = db.close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters