refactor: replace unMock with Hilt testing

This commit is contained in:
andrekir 2024-07-28 09:02:17 -03:00 committed by Andre K
parent e4c6000a10
commit 407febc5f8
4 changed files with 34 additions and 14 deletions

View file

@ -5,20 +5,11 @@ plugins {
id "org.jetbrains.kotlin.plugin.parcelize"
id 'kotlinx-serialization'
id 'com.google.dagger.hilt.android'
id 'de.mobilej.unmock'
id 'com.google.protobuf'
id "com.google.devtools.ksp"
id "io.gitlab.arturbosch.detekt" version "1.23.6"
}
unMock {
keep "android.util.Base64"
keepStartingWith "libcore."
keep "android.net.Uri"
keepAndRename "java.nio.charset.Charsets" to "xjava.nio.charset.Charsets"
}
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
if (keystorePropertiesFile.exists()) {
@ -43,7 +34,7 @@ android {
targetSdk 34
versionCode 30318 // format is Mmmss (where M is 1+the numeric major number
versionName "2.3.18"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "com.geeksville.mesh.TestRunner"
// per https://developer.android.com/studio/write/vector-asset-studio
vectorDrawables.useSupportLibrary = true
@ -186,6 +177,8 @@ dependencies {
implementation "com.google.dagger:hilt-android:$hilt_version"
implementation "androidx.hilt:hilt-navigation-compose:1.2.0"
ksp "com.google.dagger:hilt-compiler:$hilt_version"
androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
kspAndroidTest "com.google.dagger:hilt-compiler:$hilt_version"
// Navigation
def nav_version = "2.7.7"

View file

@ -1,11 +1,28 @@
package com.geeksville.mesh.model
package com.geeksville.mesh
import android.net.Uri
import com.geeksville.mesh.model.getChannelUrl
import com.geeksville.mesh.model.primaryChannel
import com.geeksville.mesh.model.shouldAddChannels
import com.geeksville.mesh.model.toChannelSet
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@HiltAndroidTest
class ChannelSetTest {
@get:Rule
var hiltRule = HiltAndroidRule(this)
@Before
fun init() {
hiltRule.inject()
}
/** make sure we match the python and device code behavior */
@Test
fun matchPython() {

View file

@ -0,0 +1,13 @@
package com.geeksville.mesh
import android.app.Application
import android.content.Context
import androidx.test.runner.AndroidJUnitRunner
import dagger.hilt.android.testing.HiltTestApplication
@Suppress("unused")
class TestRunner : AndroidJUnitRunner() {
override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application {
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
}
}

View file

@ -29,9 +29,6 @@ buildscript {
// protobuf plugin - docs here https://github.com/google/protobuf-gradle-plugin
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.9.4'
// for unit testing https://github.com/bjoernQ/unmock-plugin
classpath 'com.github.bjoernq:unmockplugin:0.8.0'
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
}
}