File tree Expand file tree Collapse file tree 3 files changed +12
-1
lines changed
src/test/java/jp/studyplus/android/sdk Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,12 @@ android {
60
60
}
61
61
}
62
62
}
63
+
64
+ testOptions {
65
+ unitTests {
66
+ includeAndroidResources = true
67
+ }
68
+ }
63
69
}
64
70
65
71
dependencies {
@@ -74,6 +80,7 @@ dependencies {
74
80
implementation " com.squareup.okhttp3:okhttp:$okhttp "
75
81
76
82
testImplementation ' junit:junit:4.12'
83
+ testImplementation ' org.robolectric:robolectric:4.0.2'
77
84
testImplementation " org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version "
78
85
testImplementation " com.squareup.okhttp3:mockwebserver:$okhttp "
79
86
}
Original file line number Diff line number Diff line change @@ -4,9 +4,12 @@ import jp.studyplus.android.sdk.internal.api.MockApiClient
4
4
import jp.studyplus.android.sdk.record.StudyRecordBuilder
5
5
import kotlinx.coroutines.runBlocking
6
6
import org.junit.Test
7
+ import org.junit.runner.RunWith
8
+ import org.robolectric.RobolectricTestRunner
7
9
import kotlin.test.assertEquals
8
10
import kotlin.test.assertNull
9
11
12
+ @RunWith(RobolectricTestRunner ::class )
10
13
class ApiUnitTest {
11
14
12
15
@Test
Original file line number Diff line number Diff line change @@ -5,12 +5,13 @@ import okhttp3.OkHttpClient
5
5
import okhttp3.Request
6
6
import okhttp3.mockwebserver.MockResponse
7
7
import okhttp3.mockwebserver.MockWebServer
8
+ import org.json.JSONObject
8
9
9
10
internal class MockApiService (private val client : OkHttpClient ) {
10
11
11
12
fun post (json : String ): Deferred <Long ?> {
12
13
val server = MockWebServer ()
13
- server.enqueue(MockResponse ().setBody(""" "{ "record_id": 9999L} """ ))
14
+ server.enqueue(MockResponse ().setBody(JSONObject (). apply { put( " record_id" , 9999L ) }.toString() ))
14
15
server.start()
15
16
16
17
val body = createPostBody(json)
You can’t perform that action at this time.
0 commit comments