Skip to content
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

Setup unit testing for core/network module [MW-208] #1848

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

meetjain6091
Copy link

@meetjain6091 meetjain6091 commented Feb 6, 2025

Issue Fix

Fixes #208
JIRA Task: MW-208

Screenshots

N/A (Unit test setup)

Description

  • Added unit testing setup for the core/network module.
  • Configured dependencies for Kotlin test, JUnit, and MockK.
  • Implemented a sample test case in NetworkClientTest.kt to validate the setup.
  • Updated build.gradle.kts to include test dependencies.

Checklist

  • Apply the AndroidStyle.xml style template to your code in Android Studio.
  • Run the unit tests with ./gradlew check to make sure you didn't break anything.
  • If you have multiple commits, please combine them into one commit by squashing them.

testImplementation ("io.mockk:mockk:1.13.4") // Mocking library
testImplementation ("androidx.test.ext:junit:1.1.5") // JUnit for Android
testImplementation ("androidx.test:core:1.4.0") // For Android testing support
Copy link

@HekmatullahAmin HekmatullahAmin Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meetjain6091 I noticed that the test dependencies are currently in the dependencies {} block, but since this is a Kotlin Multiplatform (KMP) project, it would be better to place them inside the kotlin {} block under commonTest and androidTest.

like this:

kotlin {

sourceSets {
    commonTest.dependencies {
        implementation("org.jetbrains.kotlin:kotlin-test:1.8.21")
        implementation("io.mockk:mockk:1.13.4")  // Mocking library
    }

    androidTest.dependencies {
        implementation("androidx.test.ext:junit:1.1.5")
        implementation("androidx.test:core:1.4.0")
    }
}

}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay will surely update it

@meetjain6091
Copy link
Author

meetjain6091 commented Feb 7, 2025 via email

@HekmatullahAmin
Copy link

hello hekmatullah, i was trying to do it but androidTest is giving issues i tried to understand about kmp project so it is not a necessary to be in kotlin{} format but it is better right??

Hey @meetjain6091 ,

Regarding your question, I’d suggest you go through this article it gives a brief but clear understanding of KMP, and @therajanmaurya sir also mentioned it in Slack. It will help you understand where to put each dependency properly.

Also, don’t copy paste all dependencies at once. Instead, add them one by one and understand their purpose. As far as I know, Rajan sir suggested adding a small piece of code and testing it for now. You can start with this in commonTest dependency:

implementation(kotlin("test-common"))

Then, write a small test like I did (I also shared a pic of it with you). Remember, every dependency should be placed in its specific source set.

Hope this helps! Let me know if you run into any issues.

Screenshot 2025-02-07 at 16 05 45

@meetjain6091
Copy link
Author

meetjain6091 commented Feb 7, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants