Skip to content

Commit

Permalink
Get Junit5 tests working for DataSourceModule
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuester committed Jan 18, 2025
1 parent ea2adfe commit 04275e6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ android {
jvmTarget = JavaVersion.VERSION_17.toString()
}
testOptions {
unitTests.isIncludeAndroidResources = true
unitTests.all {
it.useJUnitPlatform()
}
}
lint {
warningsAsErrors = true
Expand Down Expand Up @@ -110,7 +112,8 @@ dependencies {
// Test libs
testImplementation(kotlin("test"))
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
testImplementation("io.mockk:mockk:1.13.14")
testImplementation("io.mockk:mockk-android:1.13.14")
testImplementation("io.mockk:mockk-agent:1.13.14")
}
protobuf {
protoc {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.jkuester.unlauncher.datasource

import android.content.Context
import androidx.datastore.core.DataStore
import com.jkuester.unlauncher.datastore.CorePreferences
import com.jkuester.unlauncher.datastore.QuickButtonPreferences
import com.jkuester.unlauncher.datastore.UnlauncherApps
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import io.mockk.verify
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertInstanceOf
import org.junit.jupiter.api.extension.ExtendWith

@MockKExtension.CheckUnnecessaryStub
@MockKExtension.ConfirmVerification
@ExtendWith(MockKExtension::class)
class DataSourceModuleTest {
private val dataStoreModule = DataStoreModule()

@MockK
lateinit var appContext: Context

@BeforeEach
fun beforeEach() {
every { appContext.applicationContext } returns appContext
}

@AfterEach
fun afterEach() {
verify { appContext.applicationContext }
}

@Test
fun provideQuickButtonPreferencesStore() {
val actualStore = dataStoreModule.provideQuickButtonPreferencesStore(appContext)
assertInstanceOf<DataStore<QuickButtonPreferences>>(actualStore)
}

@Test
fun provideUnlauncherAppsStore() {
val actualStore = dataStoreModule.provideUnlauncherAppsStore(appContext)
assertInstanceOf<DataStore<UnlauncherApps>>(actualStore)
}

@Test
fun provideCorePreferencesStore() {
val actualStore = dataStoreModule.provideCorePreferencesStore(appContext)
assertInstanceOf<DataStore<CorePreferences>>(actualStore)
}
}
3 changes: 0 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ allprojects {
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
tasks.register("test", Test::class) {
useJUnitPlatform()
}

plugins {
id("com.google.devtools.ksp") version "2.1.0-1.0.29" apply false // This needs to match kotlin-stdlib
Expand Down

0 comments on commit 04275e6

Please sign in to comment.