Robolectric coverage for SpeechRecognitionService#21
Closed
ivan-digital wants to merge 0 commit into
Closed
Conversation
This was referenced May 9, 2026
Contributor
Author
40d78b8 to
5a323d6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on top of #19. Adds JVM unit-test coverage for the new
SpeechRecognitionServiceand the regressions fixed in 1504fba(stop-hang, start-race).
Summary
SpeechPipelinefrom class to interface + internalSpeechPipelineImpl. The factorySpeechPipeline(config)is preservedvia a companion
invoke, so the demo app and existingandroidTestcall sites compile unchanged.
SpeechRecognitionServicefor test subclassing. Extract threeprotected seams —
createPipeline,resolveModelDir,newAudioRecord— so JVM tests can run without loading the native library, downloading
models, or opening a real microphone.
androidx.test:coreto the:sdktestclasspath; enable
unitTests.isIncludeAndroidResources.Tests added
SpeechRecognitionServiceTest(5 tests, all run on the JVM in <1 s each):startListening_setsUpPipelineAndSignalsReadyreadyForSpeechfires after pipeline initstartListening_concurrentCallReturnsBusyERROR_RECOGNIZER_BUSYstopListening_flushesPipelineWithSilenceonStopListeningstartListening_withoutPermission_reportsInsufficienttranscriptionCompleted_emitsResultsAndTearsDownSessionresults(...)and closes the pipelineTests use a
TestableServicesubclass that overrides the seams, aFakeSpeechPipelineimplementing the new interface, and a MockK-mockedAudioRecord(returnsSTATE_INITIALIZED,readreturns-1so themic loop exits cleanly).
Test plan
./gradlew :sdk:testDebugUnitTest— 20/20 pass (5 new + 15 existing)./gradlew :sdk:assembleDebug— green./gradlew :app:assembleDebug— green (verifies theSpeechPipelineinterface refactor doesn't break demo-app callers)./gradlew :sdk:connectedDebugAndroidTest— 34/34 pass on an arm64 emulator (verifies the existingandroidTestsuite still runs against the interface)Notes
feat/recognition-serviceso the diff stays focused.Retarget to
mainafter Add Android RecognitionService for system-wide voice input #19 merges, or squash both branches into onePR if preferred.
RecognitionService.Callbackhas a package-private constructor; MockKhandles this via its agent. If CI surfaces issues, an alternative is
to wrap
Callbackbehind a thin testable façade — happy to follow up.