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 1fd280b
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/blank.yml → .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
- name: Build with Gradle
run: ./gradlew build

# Runs the entire unit test suite
- name: Run Unit Tests
run: ./gradlew test

# # Runs a set of commands using the runners shell
# - name: Upload a Build Artifact
# uses: actions/[email protected]
Expand Down
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,46 @@
package com.compose.weatherapplite.utils

import io.mockk.impl.annotations.RelaxedMockK
import java.time.LocalDate
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Test

class GenericExtensionsTest {

@RelaxedMockK
private val date = LocalDate.now()

@RelaxedMockK
private val mockedPastDate = LocalDate.now().minusDays(1)

@RelaxedMockK
private val mockedFutureDate = LocalDate.now().plusDays(1)

@Test
fun `toDayOfWeek returns Today for current date`() {
// Action
val result = date.toDayOfWeek()

// Assert
assertEquals("Today", result)
}

@Test
fun `toDayOfWeek returns correct day name for past date`() {
// Action
val result = mockedPastDate.toDayOfWeek()

// Assert
assertNotEquals("Today", result)
}

@Test
fun `toDayOfWeek returns correct day name for future date`() {
// Action
val result = mockedFutureDate.toDayOfWeek()

// Assert
assertNotEquals("Today", result)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
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`() {
// Action
val result = WeatherType.ClearSky.toDrawable()

// Assert
assertEquals(R.drawable.vd_clear_sky, result)
}

@Test
fun `toDrawable returns correct drawable for Overcast`() {
// Action
val result = WeatherType.Overcast.toDrawable()

// Assert
assertEquals(R.drawable.vd_overcast, result)
}

@Test
fun `toDrawable returns correct drawable for Foggy`() {
// Action
val result = WeatherType.Foggy.toDrawable()

// Assert
assertEquals(R.drawable.vd_foggy, result)
}

@Test
fun `toDrawable returns correct drawable for Drizzle`() {
// Action
val result = WeatherType.Drizzle.toDrawable()

// Assert
assertEquals(R.drawable.vd_drizzle, result)
}

@Test
fun `toDrawable returns correct drawable for Rain`() {
// Action
val result = WeatherType.Rain.toDrawable()

// Assert
assertEquals(R.drawable.vd_rain, result)
}

@Test
fun `toDrawable returns correct drawable for HeavyRain`() {
// Action
val result = WeatherType.HeavyRain.toDrawable()

// Assert
assertEquals(R.drawable.vd_heavy_rain, result)
}

@Test
fun `toDrawable returns correct drawable for SnowFall`() {
// Action
val result = WeatherType.SnowFall.toDrawable()

// Assert
assertEquals(R.drawable.vd_snowfall, result)
}

@Test
fun `toDrawable returns correct drawable for Thunderstorm`() {
// Action
val result = WeatherType.Thunderstorm.toDrawable()

// Assert
assertEquals(R.drawable.vd_thunderstorm, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for ClearSky`() {
// Action
val result = WeatherType.ClearSky.toAnimatedVectorDrawable()

// Assert
assertEquals(R.drawable.avd_clear_sky, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for Overcast`() {
// Action
val result = WeatherType.Overcast.toAnimatedVectorDrawable()

// Assert
assertEquals(R.drawable.avd_overcast, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for Foggy`() {
// Action
val result = WeatherType.Foggy.toAnimatedVectorDrawable()

// Assert
assertEquals(R.drawable.avd_foggy, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for Drizzle`() {
// Action
val result = WeatherType.Drizzle.toAnimatedVectorDrawable()

// Assert
assertEquals(R.drawable.avd_drizzle, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for Rain`() {
// Action
val result = WeatherType.Rain.toAnimatedVectorDrawable()

// Assert
assertEquals(R.drawable.avd_rain, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for HeavyRain`() {
// Action
val result = WeatherType.HeavyRain.toAnimatedVectorDrawable()

// Assert
assertEquals(R.drawable.avd_heavy_rain, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for SnowFall`() {
// Action
val result = WeatherType.SnowFall.toAnimatedVectorDrawable()

// Assert
assertEquals(R.drawable.avd_snowfall, result)
}

@Test
fun `toAnimatedVectorDrawable returns correct drawable for Thunderstorm`() {
// Action
val result = WeatherType.Thunderstorm.toAnimatedVectorDrawable()

// Assert
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 1fd280b

Please sign in to comment.