Skip to content

Commit 67dfdc6

Browse files
committed
feat: search room test code 작성중
1 parent 67d2067 commit 67dfdc6

6 files changed

Lines changed: 102 additions & 25 deletions

File tree

app/build.gradle

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ android {
4545
}
4646

4747
dependencies {
48-
def room_version = "2.2.5"
48+
def room_version = "2.2.3"
4949

5050
implementation fileTree(dir: 'libs', include: ['*.jar'])
5151
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
@@ -60,21 +60,24 @@ dependencies {
6060
// room
6161
implementation "androidx.room:room-runtime:$room_version"
6262
kapt "androidx.room:room-compiler:$room_version"
63+
androidTestImplementation "androidx.room:room-testing:2.2.3"
64+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
65+
androidTestImplementation "org.koin:koin-test:2.0.1"
66+
androidTestImplementation "org.mockito:mockito-core:2.25.0"
6367

6468
// test implementation
65-
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
66-
testImplementation 'junit:junit:4.12'
67-
testImplementation 'org.robolectric:robolectric:4.3'
68-
testImplementation 'org.powermock:powermock-api-mockito:1.4.12'
69-
testImplementation 'org.powermock:powermock-module-junit4:1.6.2'
70-
testImplementation 'org.mockito:mockito-core:2.28.2'
71-
testImplementation 'androidx.arch.core:core-testing:2.1.0'
72-
androidTestImplementation 'androidx.test:runner:1.2.0'
73-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
74-
androidTestImplementation 'androidx.test:rules:1.2.0'
75-
androidTestImplementation 'androidx.test:core:1.2.0'
76-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
77-
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
69+
// implementation 'androidx.legacy:legacy-support-v4:1.0.0'
70+
// testImplementation 'junit:junit:4.12'
71+
// testImplementation 'org.robolectric:robolectric:4.3'
72+
// testImplementation 'org.powermock:powermock-api-mockito:1.4.12'
73+
// testImplementation 'org.powermock:powermock-module-junit4:1.6.2'
74+
// testImplementation 'androidx.arch.core:core-testing:2.1.0'
75+
// androidTestImplementation 'androidx.test:runner:1.2.0'
76+
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
77+
// androidTestImplementation 'androidx.test:rules:1.2.0'
78+
// androidTestImplementation 'androidx.test:core:1.2.0'
79+
// androidTestImplementation 'androidx.test.ext:junit:1.1.1'
80+
// androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
7881

7982
// Google Ads
8083
implementation 'com.google.android.gms:play-services-ads:18.2.0'
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.seok.gfd.room.dao
2+
3+
import androidx.room.Room
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import androidx.test.platform.app.InstrumentationRegistry
6+
import com.seok.gfd.room.AppDatabase
7+
import com.seok.gfd.room.entity.SearchGithubId
8+
import org.junit.After
9+
import org.junit.Before
10+
11+
import org.junit.Assert.*
12+
import org.junit.Test
13+
import org.junit.runner.RunWith
14+
import java.io.IOException
15+
import java.util.*
16+
17+
@RunWith(AndroidJUnit4::class)
18+
class SearchGithubIdDaoTest {
19+
private lateinit var githubIdDao: SearchGithubIdDao
20+
private lateinit var db : AppDatabase
21+
22+
@Before
23+
fun createDb() {
24+
val context = InstrumentationRegistry.getInstrumentation().targetContext
25+
db = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java).build()
26+
githubIdDao = db.searchGithubDao()
27+
}
28+
29+
@After
30+
@Throws(IOException::class)
31+
fun closeDb(){
32+
db.close()
33+
}
34+
35+
@Test
36+
@Throws(Exception::class)
37+
fun write(){
38+
val searchGithubId : SearchGithubId = SearchGithubId(1, "2", Date())
39+
githubIdDao.insertSearchGithubId(searchGithubId)
40+
val byName = githubIdDao.selectGithubIds("2")
41+
println(byName)
42+
}
43+
44+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.seok.gfd.room
2+
3+
import androidx.room.Database
4+
import androidx.room.RoomDatabase
5+
import com.seok.gfd.room.dao.SearchGithubIdDao
6+
import com.seok.gfd.room.entity.SearchGithubId
7+
8+
@Database(entities = [SearchGithubId::class], version = 1)
9+
abstract class AppDatabase : RoomDatabase() {
10+
abstract fun searchGithubDao() : SearchGithubIdDao
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.seok.gfd.room.dao
2+
3+
import androidx.room.*
4+
import com.seok.gfd.room.entity.SearchGithubId
5+
import java.util.*
6+
7+
@Dao
8+
abstract class SearchGithubIdDao {
9+
@Insert(onConflict = OnConflictStrategy.REPLACE)
10+
abstract fun insertSearchGithubId(searchGithubId: SearchGithubId)
11+
12+
@Delete
13+
abstract fun deleteSearchGithubId(searchGithubId: SearchGithubId)
14+
15+
@Query("SELECT * FROM search_github_ids WHERE gid_name = :gidName")
16+
abstract fun selectGithubIds(gidName : String) : List<SearchGithubId>
17+
}

app/src/main/java/com/seok/gfd/room/entity/GithubID.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.seok.gfd.room.entity
2+
3+
import androidx.room.ColumnInfo
4+
import androidx.room.Entity
5+
import androidx.room.PrimaryKey
6+
import java.util.*
7+
8+
@Entity(tableName = "search_github_ids")
9+
data class SearchGithubId(
10+
@PrimaryKey var gid: Int,
11+
@ColumnInfo(name = "gid_name") val gidName: String?,
12+
@ColumnInfo(name = "created", defaultValue = "CURRENT_TIMESTAMP") val created: Date?
13+
)

0 commit comments

Comments
 (0)