Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestFixtures refactoring #1515

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ dependencies {
implementation(projects.core.data)
implementation(projects.core.model)
implementation(projects.core.analytics)
implementation(projects.sync.work)
implementation(projects.sync)

implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.material3.adaptive)
Expand All @@ -105,30 +105,32 @@ dependencies {
implementation(libs.coil.kt)

ksp(libs.hilt.compiler)
kspTest(libs.hilt.compiler)
kspAndroidTest(libs.hilt.compiler)

debugImplementation(libs.androidx.compose.ui.testManifest)
debugImplementation(projects.uiTestHiltManifest)

kspTest(libs.hilt.compiler)

testImplementation(projects.core.dataTest)
testImplementation(projects.core.testing)
testImplementation(projects.sync.syncTest)
testImplementation(libs.androidx.compose.ui.test)
testImplementation(libs.androidx.work.testing)
testImplementation(libs.hilt.android.testing)
testImplementation(testFixtures(projects.core.data))
testImplementation(testFixtures(projects.sync))

testDemoImplementation(libs.robolectric)
testDemoImplementation(libs.roborazzi)
testDemoImplementation(projects.core.screenshotTesting)
testDemoImplementation(testFixtures(projects.core.data))

androidTestImplementation(projects.core.testing)
androidTestImplementation(projects.core.dataTest)
androidTestImplementation(projects.core.datastoreTest)
androidTestImplementation(libs.androidx.test.espresso.core)
androidTestImplementation(libs.androidx.navigation.testing)
androidTestImplementation(libs.androidx.compose.ui.test)
androidTestImplementation(libs.hilt.android.testing)
androidTestImplementation(testFixtures(projects.core.data))
androidTestImplementation(testFixtures(projects.core.datastore))
androidTestImplementation(testFixtures(projects.sync))

baselineProfile(projects.benchmarks)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import androidx.navigation.compose.composable
import androidx.navigation.createGraph
import androidx.navigation.testing.TestNavHostController
import com.google.samples.apps.nowinandroid.core.data.repository.CompositeUserNewsResourceRepository
import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository
import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository
import com.google.samples.apps.nowinandroid.core.testing.util.TestNetworkMonitor
import com.google.samples.apps.nowinandroid.core.testing.util.TestTimeZoneMonitor
import com.google.samples.apps.nowinandroid.core.data.repository.TestNewsRepository
import com.google.samples.apps.nowinandroid.core.data.repository.TestUserDataRepository
import com.google.samples.apps.nowinandroid.core.data.util.TestNetworkMonitor
import com.google.samples.apps.nowinandroid.core.data.util.TestTimeZoneMonitor
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.UnconfinedTestDispatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.window.core.layout.WindowSizeClass
import com.github.takahirom.roborazzi.captureRoboImage
import com.google.samples.apps.nowinandroid.core.data.repository.FakeUserDataRepository
import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository
import com.google.samples.apps.nowinandroid.core.data.repository.UserNewsResourceRepository
import com.google.samples.apps.nowinandroid.core.data.test.repository.FakeUserDataRepository
import com.google.samples.apps.nowinandroid.core.data.util.NetworkMonitor
import com.google.samples.apps.nowinandroid.core.data.util.TimeZoneMonitor
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
Expand Down
5 changes: 5 additions & 0 deletions core/analytics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ plugins {

android {
namespace = "com.google.samples.apps.nowinandroid.core.analytics"
testFixtures.enable = true
}

dependencies {
implementation(libs.androidx.compose.runtime)

prodImplementation(platform(libs.firebase.bom))
prodImplementation(libs.firebase.analytics)

testFixturesImplementation(libs.androidx.compose.runtime) {
because("https://issuetracker.google.com/issues/259523353#comment32")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
* limitations under the License.
*/

package com.google.samples.apps.nowinandroid.core.testing.util

import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsEvent
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsHelper
package com.google.samples.apps.nowinandroid.core.analytics

class TestAnalyticsHelper : AnalyticsHelper {

Expand Down
3 changes: 0 additions & 3 deletions core/data-test/README.md

This file was deleted.

29 changes: 0 additions & 29 deletions core/data-test/build.gradle.kts

This file was deleted.

17 changes: 0 additions & 17 deletions core/data-test/src/main/AndroidManifest.xml

This file was deleted.

7 changes: 6 additions & 1 deletion core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ android {
isReturnDefaultValues = true
}
}
testFixtures.enable = true
}

dependencies {
Expand All @@ -41,6 +42,10 @@ dependencies {

testImplementation(libs.kotlinx.coroutines.test)
testImplementation(libs.kotlinx.serialization.json)
testImplementation(projects.core.datastoreTest)
testImplementation(projects.core.testing)
testImplementation(testFixtures(projects.core.datastore))
testImplementation(testFixtures(projects.core.notifications))

kspTestFixtures(libs.hilt.compiler)
testFixturesImplementation(libs.hilt.android.testing)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,23 @@ import dagger.hilt.components.SingletonComponent
abstract class DataModule {

@Binds
internal abstract fun bindsTopicRepository(
topicsRepository: OfflineFirstTopicsRepository,
): TopicsRepository
internal abstract fun bindsTopicRepository(it: OfflineFirstTopicsRepository): TopicsRepository

@Binds
internal abstract fun bindsNewsResourceRepository(
newsRepository: OfflineFirstNewsRepository,
): NewsRepository
internal abstract fun bindsNewsResourceRepository(it: OfflineFirstNewsRepository): NewsRepository

@Binds
internal abstract fun bindsUserDataRepository(
userDataRepository: OfflineFirstUserDataRepository,
): UserDataRepository
internal abstract fun bindsUserDataRepository(it: OfflineFirstUserDataRepository): UserDataRepository

@Binds
internal abstract fun bindsRecentSearchRepository(
recentSearchRepository: DefaultRecentSearchRepository,
): RecentSearchRepository
internal abstract fun bindsRecentSearchRepository(it: DefaultRecentSearchRepository): RecentSearchRepository

@Binds
internal abstract fun bindsSearchContentsRepository(
searchContentsRepository: DefaultSearchContentsRepository,
): SearchContentsRepository
internal abstract fun bindsSearchContentsRepository(it: DefaultSearchContentsRepository): SearchContentsRepository

@Binds
internal abstract fun bindsNetworkMonitor(
networkMonitor: ConnectivityManagerNetworkMonitor,
): NetworkMonitor
internal abstract fun bindsNetworkMonitor(it: ConnectivityManagerNetworkMonitor): NetworkMonitor

@Binds
internal abstract fun binds(impl: TimeZoneBroadcastMonitor): TimeZoneMonitor
internal abstract fun bindsTimeZoneMonitor(it: TimeZoneBroadcastMonitor): TimeZoneMonitor
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package com.google.samples.apps.nowinandroid.core.data

import com.google.samples.apps.nowinandroid.core.data.repository.CompositeUserNewsResourceRepository
import com.google.samples.apps.nowinandroid.core.data.repository.NewsResourceQuery
import com.google.samples.apps.nowinandroid.core.data.repository.TestNewsRepository
import com.google.samples.apps.nowinandroid.core.data.repository.TestUserDataRepository
import com.google.samples.apps.nowinandroid.core.data.repository.emptyUserData
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
import com.google.samples.apps.nowinandroid.core.model.data.Topic
import com.google.samples.apps.nowinandroid.core.model.data.mapToUserNewsResources
import com.google.samples.apps.nowinandroid.core.testing.repository.TestNewsRepository
import com.google.samples.apps.nowinandroid.core.testing.repository.TestUserDataRepository
import com.google.samples.apps.nowinandroid.core.testing.repository.emptyUserData
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Instant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import com.google.samples.apps.nowinandroid.core.database.model.PopulatedNewsRes
import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity
import com.google.samples.apps.nowinandroid.core.database.model.asExternalModel
import com.google.samples.apps.nowinandroid.core.datastore.NiaPreferencesDataSource
import com.google.samples.apps.nowinandroid.core.datastore.test.testUserPreferencesDataStore
import com.google.samples.apps.nowinandroid.core.datastore.di.testUserPreferencesDataStore
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
import com.google.samples.apps.nowinandroid.core.model.data.Topic
import com.google.samples.apps.nowinandroid.core.network.model.NetworkChangeList
import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource
import com.google.samples.apps.nowinandroid.core.testing.notifications.TestNotifier
import com.google.samples.apps.nowinandroid.core.notifications.TestNotifier
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.google.samples.apps.nowinandroid.core.database.dao.TopicDao
import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity
import com.google.samples.apps.nowinandroid.core.database.model.asExternalModel
import com.google.samples.apps.nowinandroid.core.datastore.NiaPreferencesDataSource
import com.google.samples.apps.nowinandroid.core.datastore.test.testUserPreferencesDataStore
import com.google.samples.apps.nowinandroid.core.datastore.di.testUserPreferencesDataStore
import com.google.samples.apps.nowinandroid.core.model.data.Topic
import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic
import kotlinx.coroutines.flow.first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.google.samples.apps.nowinandroid.core.data.repository

import com.google.samples.apps.nowinandroid.core.analytics.NoOpAnalyticsHelper
import com.google.samples.apps.nowinandroid.core.datastore.NiaPreferencesDataSource
import com.google.samples.apps.nowinandroid.core.datastore.test.testUserPreferencesDataStore
import com.google.samples.apps.nowinandroid.core.datastore.di.testUserPreferencesDataStore
import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig
import com.google.samples.apps.nowinandroid.core.model.data.ThemeBrand
import com.google.samples.apps.nowinandroid.core.model.data.UserData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
* limitations under the License.
*/

package com.google.samples.apps.nowinandroid.core.data.test
package com.google.samples.apps.nowinandroid.core.data.di

import com.google.samples.apps.nowinandroid.core.data.di.DataModule
import com.google.samples.apps.nowinandroid.core.data.repository.FakeNewsRepository
import com.google.samples.apps.nowinandroid.core.data.repository.FakeRecentSearchRepository
import com.google.samples.apps.nowinandroid.core.data.repository.FakeSearchContentsRepository
import com.google.samples.apps.nowinandroid.core.data.repository.FakeTopicsRepository
import com.google.samples.apps.nowinandroid.core.data.repository.FakeUserDataRepository
import com.google.samples.apps.nowinandroid.core.data.repository.NewsRepository
import com.google.samples.apps.nowinandroid.core.data.repository.RecentSearchRepository
import com.google.samples.apps.nowinandroid.core.data.repository.SearchContentsRepository
import com.google.samples.apps.nowinandroid.core.data.repository.TopicsRepository
import com.google.samples.apps.nowinandroid.core.data.repository.UserDataRepository
import com.google.samples.apps.nowinandroid.core.data.test.repository.FakeNewsRepository
import com.google.samples.apps.nowinandroid.core.data.test.repository.FakeRecentSearchRepository
import com.google.samples.apps.nowinandroid.core.data.test.repository.FakeSearchContentsRepository
import com.google.samples.apps.nowinandroid.core.data.test.repository.FakeTopicsRepository
import com.google.samples.apps.nowinandroid.core.data.test.repository.FakeUserDataRepository
import com.google.samples.apps.nowinandroid.core.data.util.AlwaysOnlineNetworkMonitor
import com.google.samples.apps.nowinandroid.core.data.util.DefaultZoneIdTimeZoneMonitor
import com.google.samples.apps.nowinandroid.core.data.util.NetworkMonitor
import com.google.samples.apps.nowinandroid.core.data.util.TimeZoneMonitor
import dagger.Binds
Expand All @@ -39,37 +40,25 @@ import dagger.hilt.testing.TestInstallIn
components = [SingletonComponent::class],
replaces = [DataModule::class],
)
internal interface TestDataModule {
interface TestDataModule {
@Binds
fun bindsTopicRepository(
fakeTopicsRepository: FakeTopicsRepository,
): TopicsRepository
fun bindsTopicRepository(it: FakeTopicsRepository): TopicsRepository

@Binds
fun bindsNewsResourceRepository(
fakeNewsRepository: FakeNewsRepository,
): NewsRepository
fun bindsNewsResourceRepository(it: FakeNewsRepository): NewsRepository

@Binds
fun bindsUserDataRepository(
userDataRepository: FakeUserDataRepository,
): UserDataRepository
fun bindsUserDataRepository(it: FakeUserDataRepository): UserDataRepository

@Binds
fun bindsRecentSearchRepository(
recentSearchRepository: FakeRecentSearchRepository,
): RecentSearchRepository
fun bindsRecentSearchRepository(it: FakeRecentSearchRepository): RecentSearchRepository

@Binds
fun bindsSearchContentsRepository(
searchContentsRepository: FakeSearchContentsRepository,
): SearchContentsRepository
fun bindsSearchContentsRepository(it: FakeSearchContentsRepository): SearchContentsRepository

@Binds
fun bindsNetworkMonitor(
networkMonitor: AlwaysOnlineNetworkMonitor,
): NetworkMonitor
fun bindsNetworkMonitor(it: AlwaysOnlineNetworkMonitor): NetworkMonitor

@Binds
fun binds(impl: DefaultZoneIdTimeZoneMonitor): TimeZoneMonitor
fun bindsTimeZoneMonitor(it: DefaultZoneIdTimeZoneMonitor): TimeZoneMonitor
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
* limitations under the License.
*/

package com.google.samples.apps.nowinandroid.core.data.test.repository
package com.google.samples.apps.nowinandroid.core.data.repository

import com.google.samples.apps.nowinandroid.core.data.Synchronizer
import com.google.samples.apps.nowinandroid.core.data.model.asEntity
import com.google.samples.apps.nowinandroid.core.data.repository.NewsRepository
import com.google.samples.apps.nowinandroid.core.data.repository.NewsResourceQuery
import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEntity
import com.google.samples.apps.nowinandroid.core.database.model.asExternalModel
import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
* limitations under the License.
*/

package com.google.samples.apps.nowinandroid.core.data.test.repository
package com.google.samples.apps.nowinandroid.core.data.repository

import com.google.samples.apps.nowinandroid.core.data.model.RecentSearchQuery
import com.google.samples.apps.nowinandroid.core.data.repository.RecentSearchRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import javax.inject.Inject

/**
* Fake implementation of the [RecentSearchRepository]
*/
internal class FakeRecentSearchRepository @Inject constructor() : RecentSearchRepository {
class FakeRecentSearchRepository @Inject constructor() : RecentSearchRepository {
override suspend fun insertOrReplaceRecentSearch(searchQuery: String) = Unit

override fun getRecentSearchQueries(limit: Int): Flow<List<RecentSearchQuery>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

package com.google.samples.apps.nowinandroid.core.data.test.repository
package com.google.samples.apps.nowinandroid.core.data.repository

import com.google.samples.apps.nowinandroid.core.data.repository.SearchContentsRepository
import com.google.samples.apps.nowinandroid.core.model.data.SearchResult
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
Expand All @@ -25,7 +24,7 @@ import javax.inject.Inject
/**
* Fake implementation of the [SearchContentsRepository]
*/
internal class FakeSearchContentsRepository @Inject constructor() : SearchContentsRepository {
class FakeSearchContentsRepository @Inject constructor() : SearchContentsRepository {

override suspend fun populateFtsData() = Unit
override fun searchContents(searchQuery: String): Flow<SearchResult> = flowOf()
Expand Down
Loading
Loading