Skip to content

docs(android): add Unit Testing guide [SDC-31985]#377

Open
redwarp wants to merge 5 commits into
mainfrom
feature/SDC-31985-android-unit-testing-docs
Open

docs(android): add Unit Testing guide [SDC-31985]#377
redwarp wants to merge 5 commits into
mainfrom
feature/SDC-31985-android-unit-testing-docs

Conversation

@redwarp

@redwarp redwarp commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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

  • Two approaches (use either/both): isolate the SDK behind your own abstraction, or mock its types.
  • Why the SDK's modes/sessions/results must be mocked on Android: they're final and call native code on construction, so real construction throws UnsatisfiedLinkError on the host JVM.
  • MockK and Mockito (inline) examples, in synced tabs, for every mode the ticket covers — Barcode Capture, MatrixScan (BarcodeBatch), ID Capture, SparkScan — plus BarcodePick, FrameData, and Feedback.
  • Instrumented tests for what can't run on the JVM: real settings, a real BarcodeCountView, and real decoding via BitmapFrameSource.
  • Tips/pitfalls (e.g. avoid relaxed = true on native-backed mocks; background-thread callbacks).

Validation tooling

The snippet validator gained two changes so these examples compile against the real SDK in CI:

  • test/mocking libs (MockK, Mockito, kotlin-test, JUnit, androidx.test) added to the snippet test-bed; kotlinc pinned to 2.4.0 (matching kotlin-test); -jvm-target 11 for MockK's inline functions.
  • top-level interface declarations are hoisted to package scope (Kotlin forbids local interfaces).

All snippets compile: validate-code-snippets.py kotlin161 passed, 0 failed. Verified locally and under act with the CI toolchain.

🤖 Generated with Claude Code

redwarp and others added 5 commits June 24, 2026 17:28
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>
@redwarp redwarp requested a review from raffaelefarinaro June 25, 2026 13:25
@redwarp

redwarp commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@marcozoffoli-scandit FYI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant