Provider
Testing a provider#
This guide covers testing tips for provider development, focusing on unit testing and in-app testing.
Unit testing (recommended)#
When possible, unit test your capability API classes directly (e.g., SearchProviderApi implementation classes).
ProviderPlugin.manifest and ProviderPlugin.settings are initialized by the host app at runtime.
Because those are lateinit, you generally should not instantiate ProviderPlugin in unit tests.
Prefer testing the capability API classes in isolation.
Example: unit test a search implementation.
class TestProviderSearchProviderApiTest {
private val api = TestProviderSearchProviderApi(
providerId = "prov-test-provider",
)
@Test
fun `search returns results`() = runBlocking {
val response = api.search(
title = "test",
page = 1,
filters = api.filters,
)
assert(response.results.isNotEmpty())
}
}In-app testing#
Flixclusive includes a built-in way to test a provider after deployment.
- Build/package your provider:
./gradlew :TestProvider:make - Deploy to device/emulator:
./gradlew :TestProvider:deployWithAdb
If you are using the debug build of the app:
./gradlew :TestProvider:deployWithAdb --debug-appIf you want to attach a debugger:
./gradlew :TestProvider:deployWithAdb --wait-for-debuggerLegacy ProviderApi.testFilm (optional)#
If your provider still implements the deprecated ProviderApi via ProviderPlugin.getApi(context, client),
you can customize the testFilm used by older test flows.
For new providers, prefer ensuring your capability APIs behave correctly for at least one known title/ID.
Debugging tips#
- Use Android Studio’s debugger with
--wait-for-debugger. - Prefer deterministic failures (throw clear exceptions) over silent empty results.
- Use built-in logging utilities from
com.flixclusive.core.util.log:
// Debug logs
debugLog("Loading search results...")
takeIf { response.results.isEmpty() }?.let {
warnLog("Search returned no results")
}
// Error logs
try {
// ...
} catch (e: Exception) {
errorLog(e)
}