Skip to content

Commit

Permalink
Move robolectric tests to Shared module
Browse files Browse the repository at this point in the history
  • Loading branch information
mr3y-the-programmer committed Nov 12, 2023
1 parent c34f17c commit 67a35b2
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 40 deletions.
10 changes: 0 additions & 10 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ dependencies {
implementation(libs.views.material)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.activity.compose)
implementation(libs.splash.screen)

implementation(project(":shared"))
Expand All @@ -120,16 +119,7 @@ dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(libs.accompanist.system.ui.controller)
implementation(libs.voyager.navigator)

// Tooling
debugImplementation(compose.uiTooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)

// Local tests: jUnit, coroutines, Android runner
testImplementation(libs.junit)
testImplementation(libs.robolectric)
testImplementation(libs.androidx.test.core)
testImplementation(libs.paging.testing)
testImplementation(libs.androidx.compose.ui.test.junit4)
}
5 changes: 0 additions & 5 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
android:theme="@style/Theme.Ludi.Splash"
android:name=".LudiApplication"
tools:targetApi="31">
<!--Required for robolectric tests, otherwise tests fail with RuntimeException("Unable to resolve activity"),
see https://github.com/robolectric/robolectric/pull/4736 for details-->
<activity
android:name="androidx.activity.ComponentActivity"
android:exported="true"/>
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
2 changes: 0 additions & 2 deletions androidApp/src/test/resources/robolectric.properties

This file was deleted.

1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ junit = "junit:junit:4.13.2"
strikt = "io.strikt:strikt-core:0.34.1"
turbine = "app.cash.turbine:turbine:1.0.0"
robolectric = "org.robolectric:robolectric:4.11.1"
guava = "com.google.guava:guava:32.1.2-android"
test-parameter-injector = "com.google.testparameterinjector:test-parameter-injector:1.14"
kotlinx-coroutines-test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3"
kotlinx-serialization = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0"
Expand Down
22 changes: 20 additions & 2 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ kotlin {
implementation(libs.sqldelight.paging)

// Paging
api(libs.paging.common)
implementation(libs.paging.common)
implementation(libs.paging.compose)

// Datastore
Expand All @@ -85,7 +85,7 @@ kotlin {
// Palette
implementation(libs.kmpalette.core)
// Material3 WindowSizeClass
api(libs.material3.windowsizeclass)
implementation(libs.material3.windowsizeclass)

// Navigation
implementation(libs.voyager.navigator)
Expand Down Expand Up @@ -122,6 +122,7 @@ kotlin {

androidMain {
dependencies {
api(libs.androidx.activity.compose)
// Database driver
implementation(libs.sqldelight.android)
// Unbundled sqlite
Expand All @@ -148,6 +149,17 @@ kotlin {
}
}

val androidUnitTest by getting {
dependencies {
implementation(libs.guava)
implementation(libs.junit)
implementation(libs.robolectric)
implementation(libs.androidx.test.core)
implementation(libs.paging.testing)
implementation(libs.androidx.compose.ui.test.junit4)
}
}

val desktopMain by getting {
dependencies {
// Database driver
Expand Down Expand Up @@ -193,6 +205,12 @@ android {
kotlinCompilerExtensionVersion = versionFor(AndroidX.Compose.compiler)
}

testOptions {
unitTests {
isIncludeAndroidResources = true
}
}

namespace = "com.mr3y.ludi.shared"
}

Expand Down
5 changes: 5 additions & 0 deletions shared/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!--Required for robolectric tests, otherwise tests fail with RuntimeException("Unable to resolve activity"),
see https://github.com/robolectric/robolectric/pull/4736 for details-->
<application>
<activity android:name="androidx.activity.ComponentActivity" android:exported="true" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mr3y.ludi.ui.screens
package com.mr3y.ludi.shared.ui.screens

import androidx.compose.ui.test.junit4.createComposeRule
import org.junit.Before
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mr3y.ludi.ui.screens
package com.mr3y.ludi.shared.ui.screens

import android.content.Context
import androidx.compose.ui.semantics.Role
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mr3y.ludi.ui.screens.deals
package com.mr3y.ludi.shared.ui.screens.deals

import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
Expand All @@ -19,8 +19,7 @@ import androidx.compose.ui.test.performClick
import cafe.adriel.lyricist.LocalStrings
import com.mr3y.ludi.shared.ui.adaptive.LocalWindowSizeClass
import com.mr3y.ludi.shared.ui.resources.LudiStrings
import com.mr3y.ludi.shared.ui.screens.deals.DealsScreen
import com.mr3y.ludi.ui.screens.BaseRobolectricTest
import com.mr3y.ludi.shared.ui.screens.BaseRobolectricTest
import com.mr3y.ludi.shared.ui.theme.LudiTheme
import org.junit.Test
import org.junit.runner.RunWith
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mr3y.ludi.ui.screens.deals
package com.mr3y.ludi.shared.ui.screens.deals

import androidx.paging.LoadStates
import app.cash.paging.LoadStateLoading
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mr3y.ludi.ui.screens.onboarding
package com.mr3y.ludi.shared.ui.screens.onboarding

import androidx.paging.LoadStates
import app.cash.paging.LoadStateLoading
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mr3y.ludi.ui.screens.onboarding
package com.mr3y.ludi.shared.ui.screens.onboarding

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -12,10 +12,9 @@ import com.mr3y.ludi.shared.core.model.GameGenre
import com.mr3y.ludi.shared.ui.presenter.model.FavouriteGame
import com.mr3y.ludi.shared.ui.presenter.model.NewsDataSource
import com.mr3y.ludi.shared.ui.resources.LudiStrings
import com.mr3y.ludi.ui.screens.BaseRobolectricTest
import com.mr3y.ludi.ui.screens.onNodeWithStateDescription
import com.mr3y.ludi.shared.ui.screens.BaseRobolectricTest
import com.mr3y.ludi.shared.ui.screens.onNodeWithStateDescription
import com.mr3y.ludi.shared.ui.theme.LudiTheme
import com.mr3y.ludi.shared.ui.screens.onboarding.OnboardingScreen
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.mr3y.ludi.ui.screens.onboarding
package com.mr3y.ludi.shared.ui.screens.onboarding

import androidx.compose.ui.semantics.Role
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.hasStateDescription
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import com.mr3y.ludi.ui.screens.hasRole
import com.mr3y.ludi.shared.ui.screens.hasRole

internal fun ComposeContentTestRule.onGenre(genreStateDesc: String): SemanticsNodeInteraction {
return onNode(hasStateDescription(genreStateDesc) and hasRole(Role.Checkbox))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mr3y.ludi.ui.screens.onboarding.accessibility
package com.mr3y.ludi.shared.ui.screens.onboarding.accessibility

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -20,14 +20,14 @@ import com.mr3y.ludi.shared.core.model.GameGenre
import com.mr3y.ludi.shared.ui.presenter.model.FavouriteGame
import com.mr3y.ludi.shared.ui.presenter.model.NewsDataSource
import com.mr3y.ludi.shared.ui.resources.LudiStrings
import com.mr3y.ludi.ui.screens.BaseRobolectricTest
import com.mr3y.ludi.ui.screens.onNodeWithStateDescription
import com.mr3y.ludi.ui.screens.onboarding.FakeAllGenres
import com.mr3y.ludi.ui.screens.onboarding.FakeNewsDataSources
import com.mr3y.ludi.ui.screens.onboarding.FakeOnboardingGames
import com.mr3y.ludi.ui.screens.onboarding.FakeOnboardingState
import com.mr3y.ludi.shared.ui.screens.BaseRobolectricTest
import com.mr3y.ludi.shared.ui.screens.onNodeWithStateDescription
import com.mr3y.ludi.shared.ui.screens.onboarding.FakeAllGenres
import com.mr3y.ludi.shared.ui.screens.onboarding.FakeNewsDataSources
import com.mr3y.ludi.shared.ui.screens.onboarding.FakeOnboardingGames
import com.mr3y.ludi.shared.ui.screens.onboarding.FakeOnboardingState
import com.mr3y.ludi.shared.ui.screens.onboarding.OnboardingScreen
import com.mr3y.ludi.ui.screens.onboarding.onGenre
import com.mr3y.ludi.shared.ui.screens.onboarding.onGenre
import com.mr3y.ludi.shared.ui.theme.LudiTheme
import kotlinx.coroutines.test.runTest
import org.junit.Test
Expand Down

0 comments on commit 67a35b2

Please sign in to comment.