-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#9 Unit Testing #33
base: main
Are you sure you want to change the base?
#9 Unit Testing #33
Conversation
import kotlinx.coroutines.flow.flow | ||
import kotlinx.serialization.json.Json | ||
|
||
class FakeItemsRepository( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of FakeItemsRepository
?
@@ -61,6 +61,10 @@ kotlin { | |||
implementation(libs.compose.webview.multiplatform) | |||
implementation(libs.richeditor.compose) | |||
} | |||
commonTest.dependencies { | |||
implementation(libs.kotlin.test) | |||
implementation("app.cash.turbine:turbine:0.7.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You haven't used implementation("app.cash.turbine:turbine:0.7.0") in your changes; it can be added when needed.
// val result = if (!isComment) { | ||
// """ | ||
// {"by":"test","descendants":1,"id":$id,"kids":[1],"score":1,"time":1720481386,"title":"test","type":"story","text":"test","url":"test"} | ||
// """ | ||
// } else { | ||
// """ | ||
// {"by":"test", "id":$id, "kids":[1], "parent": 1, "time":1720481386,"title":"test","type":"comment","text":"test"} | ||
// """ | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary comments can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes.
The FakeItemsRepository
is the main blocker, duplicating many codes from ItemsRepositoryImpl
. Why do we need to do this?
We can write tests for ItemsRepositoryImpl
and use mock for your needs.
For the next steps, I'd recommend you research mock libs, I am familiar with mockk
and mockito
but I'm not sure if they support KMP projects. So maybe you can do this for me and make the new changes after your research.
Fake Repository is an alternative for mocking data, I used this alternative because neither Mockito nor Mockk support Kotlin Multiplatform tests The current secure alternative is to mock values by yourself, this is the approach of Fake Repository |
Update I don't think the approach is the most suitable solution. I checked out https://github.com/terrakok/kmp-awesome#-test, and most of them don't support Kotlin 2.0.0. 😢 I'd like to hold off for now and explore if there's a better solution available. |
Unit Testing