docs(android): add Unit Testing guide [SDC-31985]#377
Open
redwarp wants to merge 5 commits into
Open
Conversation
Let the Kotlin snippet validator compile examples that use test/mocking libraries: - add MockK, Mockito (core + kotlin), kotlin-test, JUnit and androidx.test as compileOnly deps in the snippet test-bed - pass -jvm-target 11 to kotlinc (MockK's inline functions require it) - pin CI kotlinc to 2.4.0 so it matches the kotlin-test version Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Document how to unit-test scanner listener/callback logic without a camera by mocking the SDK's final, native-backed classes with MockK or Mockito (inline), covering all scan modes plus FrameData/Feedback. Includes instrumented real-object tests and a BitmapFrameSource real-decode pattern. Linked in the Android sidebar next to Agent Skills. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- group the on-device sections under a single "Instrumented Tests" heading (real objects, real view, real decoding) with the setup and one-framework caution up front - add a real BarcodeCountView example (built via ActivityScenario) - lead with the capability instead of "This page describes…" - order the mock reasons native-construction first - trim the license note Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Interfaces can't be declared locally in Kotlin, so a snippet that defines its own interface (e.g. an app-facing abstraction) failed to compile when wrapped in the generated validate() method. Hoist top-level `interface` declarations to package scope, the same way standalone `object`s are handled. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- present two approaches up front (isolate behind your own abstraction, or mock the SDK's types), matching the iOS guide - add an "Isolate the SDK Behind Your Own Abstraction" section: a thin adapter over your own interface, tested with no SDK objects - add MockK + Mockito examples for MatrixScan (BarcodeBatch) and SparkScan so every mode the ticket covers has a snippet - note that nested SDK-produced results (e.g. a CapturedId's documents) must be mocked too, and add a threading tip for background-thread callbacks - reorganize the on-device sections under one "Instrumented Tests" heading Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
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.
Adds an Android Unit Testing page (
docs/sdks/android/unit-testing.mdx), linked in the Android sidebar next to Agent Skills. Companion to the iOS guide (SDC-31976).What it covers
finaland call native code on construction, so real construction throwsUnsatisfiedLinkErroron the host JVM.BarcodeBatch), ID Capture, SparkScan — plus BarcodePick,FrameData, andFeedback.BarcodeCountView, and real decoding viaBitmapFrameSource.relaxed = trueon native-backed mocks; background-thread callbacks).Validation tooling
The snippet validator gained two changes so these examples compile against the real SDK in CI:
kotlincpinned to 2.4.0 (matchingkotlin-test);-jvm-target 11for MockK's inline functions.interfacedeclarations are hoisted to package scope (Kotlin forbids local interfaces).All snippets compile:
validate-code-snippets.py kotlin→ 161 passed, 0 failed. Verified locally and underactwith the CI toolchain.🤖 Generated with Claude Code