Skip to content

Commit

Permalink
Integrate setup for Unit Testing - along with enabling unit testing i…
Browse files Browse the repository at this point in the history
…n CI/CD pipeline

Signed-off-by: Abhijit Naik <[email protected]>
  • Loading branch information
abhigit-hub committed Aug 20, 2024
1 parent 0f255d3 commit 2fc7f82
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ dependencies {
implementation(composeBom)
androidTestImplementation(composeBom)

// Unit Testing
testImplementation(libs.test.junit)
testImplementation(libs.test.junit.core)
testImplementation(libs.test.roboelectric)
testImplementation(libs.test.mockk)

// Tooling - Preview
debugImplementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.compose.ui.tooling.preview)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.compose.weatherapplite.utils

import com.compose.weatherapplite.R
import com.compose.weatherapplite.presentation.model.WeatherType
import org.junit.Assert.assertEquals
import org.junit.Test

class WeatherTypeExtensionsTest {

@Test
fun `toDrawable returns correct drawable for ClearSky`() {
val result = WeatherType.ClearSky.toDrawable()
assertEquals(R.drawable.vd_clear_sky, result)
}

@Test
fun `toDrawable returns correct drawable for Overcast`() {
val result = WeatherType.Overcast.toDrawable()
assertEquals(R.drawable.vd_overcast, result)
}

@Test
fun `toDrawable returns correct drawable for Foggy`() {
val result = WeatherType.Foggy.toDrawable()
assertEquals(R.drawable.vd_foggy, result)
}

@Test
fun `toDrawable returns correct drawable for Drizzle`() {
val result = WeatherType.Drizzle.toDrawable()
assertEquals(R.drawable.vd_drizzle, result)
}

@Test
fun `toDrawable returns correct drawable for Rain`() {
val result = WeatherType.Rain.toDrawable()
assertEquals(R.drawable.vd_rain, result)
}

@Test
fun `toDrawable returns correct drawable for HeavyRain`() {
val result = WeatherType.HeavyRain.toDrawable()
assertEquals(R.drawable.vd_heavy_rain, result)
}

@Test
fun `toDrawable returns correct drawable for SnowFall`() {
val result = WeatherType.SnowFall.toDrawable()
assertEquals(R.drawable.vd_snowfall, result)
}

@Test
fun `toDrawable returns correct drawable for Thunderstorm`() {
val result = WeatherType.Thunderstorm.toDrawable()
assertEquals(R.drawable.vd_thunderstorm, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for ClearSky`() {
val result = WeatherType.ClearSky.toAnimatedVectorDrawable()
assertEquals(R.drawable.avd_clear_sky, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for Overcast`() {
val result = WeatherType.Overcast.toAnimatedVectorDrawable()
assertEquals(R.drawable.avd_overcast, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for Foggy`() {
val result = WeatherType.Foggy.toAnimatedVectorDrawable()
assertEquals(R.drawable.avd_foggy, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for Drizzle`() {
val result = WeatherType.Drizzle.toAnimatedVectorDrawable()
assertEquals(R.drawable.avd_drizzle, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for Rain`() {
val result = WeatherType.Rain.toAnimatedVectorDrawable()
assertEquals(R.drawable.avd_rain, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for HeavyRain`() {
val result = WeatherType.HeavyRain.toAnimatedVectorDrawable()
assertEquals(R.drawable.avd_heavy_rain, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for SnowFall`() {
val result = WeatherType.SnowFall.toAnimatedVectorDrawable()
assertEquals(R.drawable.avd_snowfall, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for Thunderstorm`() {
val result = WeatherType.Thunderstorm.toAnimatedVectorDrawable()
assertEquals(R.drawable.avd_thunderstorm, result)
}
}
14 changes: 11 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ lifecycle = "2.7.0-beta01"
material3 = "1.1.2"
okhttp = "4.11.0"
playservicesLocation = "21.0.1"
test-junit = "4.13.2"
test-junit-core = "1.6.1"
test-robolectric = "4.3"
test-mockk = "1.13.7"
retrofit = "2.9.0"
versionCatalogUpdate = "0.8.1"

Expand Down Expand Up @@ -48,13 +52,17 @@ converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref
compose-map = { module = "com.google.maps.android:maps-compose", version.ref = "composeMap" }
destinations-core = { module = "io.github.raamcosta.compose-destinations:core", version.ref = "destinations" }
destinations-ksp = { module = "io.github.raamcosta.compose-destinations:ksp", version.ref = "destinations" }
okhttp-logging = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" }
okhttp3 = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" }
ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }
okhttp-logging = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" }
okhttp3 = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
playservices-location = { module = "com.google.android.gms:play-services-location", version.ref = "playservicesLocation" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }
test-junit = { module = "junit:junit", version.ref = "test-junit" }
test-junit-core = { module = "androidx.test:core", version.ref = "test-junit-core" }
test-roboelectric = { module = "org.robolectric:robolectric", version.ref = "test-robolectric" }
test-mockk = { module = "io.mockk:mockk", version.ref = "test-mockk" }


[plugins]
Expand Down

0 comments on commit 2fc7f82

Please sign in to comment.