Skip to content

Latest commit

 

History

History
119 lines (100 loc) · 7.47 KB

testing.md

File metadata and controls

119 lines (100 loc) · 7.47 KB

Testing

What is tested where

Module JVM (src/test) On a device (src/androidTest)
:app that every key serializes, which document the list highlights, the requests from outside the UI, the widgets' entry the platform content provider against the fixtures; saving and deleting a scan through the whole graph; the file provider, which reads the graph; the store's screenshots (skipped in any other run)
:library:domain, :library:data use cases; the path a migration gives an old document, search ranking, layered content the catalogue: migrations from every exported schema, a migrated schema against a new one, the triggers, search, the repositories, storage and thumbnails
:feature:* ViewModels, the D2 settings table, link resolution, selection decisions, what a widget shows for its size and what it lists :feature:widgets: the widgets' views, inflated as a launcher does
:core:* navigation rules and scene strategies, the theme's transitions, BaseViewModel —
:content:platform text splitting —
:composepdf layout geometry, tile planning, zoom steps, viewport, load-error classification fixtures, restoration, layout changes, content padding, gestures, extension points, scroll-to, load errors, platform content APIs
:content:api selection: carets, runs, layouts, right-to-left, across pages; text search —
:scanner:mlkit the scan result decision table, the activity-result host and process death —

The rule of thumb:

  • Decisions are pure and go on the JVM: what a touch selects, what a link does, what a result means.
  • Device tests check what only the platform can answer: what PdfRenderer reports, how Compose delivers gestures, how the engine draws, what the device's SQLite does with a query, trigger or migration.
  • A port is tested with a fake, never a mock of the framework.

Conventions

  • A test sits in the package of the class it tests, so it reaches internal code and is found beside it.
  • Shared doubles and fixtures live in one place, not copied:
    • :library:testing, which every module's tests may depend on: FakeDocumentStorage, FakeDocumentsRepository, FakeDocumentThumbnails, FakeSearchIndex, testDocument, FakePageContentProvider and textPage;
    • :library:data on a device: MigrationTestSupport.kt builds an old catalogue version from its exported schema and fills it with rows as that version stored them;
    • :core:navigation JVM: StandInKeys.kt, keys shaped like the app's, so navigation is tested without the features that own the real ones;
    • :composepdf JVM: layoutOf and threePages build a PageLayoutSnapshot as the real layout does;
    • :composepdf on a device: LongDocument and waitUntilLoaded (ViewerTestSupport.kt) and the gesture timings (GestureTimings.kt).
  • Names say the behaviour: backtick sentences on the JVM; camelCase in device tests, whose names cannot hold spaces, and throughout :composepdf, mostly device tests.
  • Comments explain why a case matters, in present tense.

The one device test that tests nothing

StoreCaptureTest (:app, package store) takes the app's screens for the Google Play screenshots. It is a device test because only a device can show the app's screens over a sample library in the brand's colors. It is skipped unless storeCaptures=true is passed, which only scripts/store/capture.mjs does, so connectedDebugAndroidTest neither takes screenshots nor touches the status bar. Details: scripts/store/README.md.

It starts the app's graph anew (appModules, with the catalogue and settings replaced), so it must not share a run with the tests that read the graph the app started.

Running

./gradlew testDebugUnitTest   # every JVM test, in every module
./gradlew connectedDebugAndroidTest         # every module with device tests
./gradlew :composepdf:connectedDebugAndroidTest \
    -Pandroid.testInstrumentationRunnerArguments.class=com.composepdf.gesture.PdfGesturesTest
  • Device tests run on every attached device, and so does installDebug. A phone paired over wireless ADB counts, even if nothing shows it. Target one with ANDROID_SERIAL (ANDROID_SERIAL=emulator-5554) and prefer the emulator unless a real device is needed.
  • The platform's text APIs need API 35+. Tests using them carry @SdkSuppress(minSdkVersion = 35).
  • The catalogue's tests also run on API 24, the oldest SQLite the app meets (3.9), where SQL that works elsewhere can fail. The AVD is a Google APIs image of API 24.
  • So do the widgets' tests: a launcher of that age refuses layout things a recent one takes and reports a widget's size differently (widgets.md).
  • So do the tests that open PDFs. Android 7's renderer crashes the process, and the whole run, after a document that fails to open or when two are drawn at once (pdf-engine.md). A test opens its renderers through PdfRenderers, like the app, or the first protected fixture takes down every test after it.
  • A run can pass without running anything. If a copy of the app is already installed, on API 24 the task's own install fails, no test runs and the build still succeeds. Uninstall com.bobbyesp.docucraft.debug and com.bobbyesp.docucraft.debug.test first, and read the number of tests in app/build/outputs/androidTest-results/connected/debug/TEST-*.xml, not the build result.
  • Reading an app file after a test: pass -Pandroid.injected.androidTest.leaveApksInstalledAfterRun=true, then adb shell run-as <package> ….

Fixtures

The viewer's test PDFs and their manifest.json (the expected position of every word and link) are in composepdf/src/androidTest/assets/fixtures/. What each covers and how to regenerate them: testing/pdf-fixtures/README.md.

Never commit a document with personal data as a fixture; build an equivalent with invented content.

Checking by hand on the emulator

Some behaviour only shows on a screen: selecting, handles, auto-scroll, link previews, Custom Tabs.

adb -s emulator-5554 push composepdf/src/androidTest/assets/fixtures/text-and-links.pdf /sdcard/Download/
adb -s emulator-5554 shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/Download/text-and-links.pdf
adb -s emulator-5554 shell content query --uri content://media/external/downloads --projection _id:_display_name
adb -s emulator-5554 shell am start -a android.intent.action.VIEW -t application/pdf \
    -d content://media/external/downloads/<id> --grant-read-uri-permission \
    -n com.bobbyesp.docucraft.debug/com.bobbyesp.docucraft.feature.pdfviewer.presentation.PdfViewerActivity
  • Gestures. input swipe for a long press; input motionevent DOWN/MOVE/UP for a drag that holds. Screenshots: exec-out screencap -p.
  • Finding things on screen. Prefer the accessibility dump (uiautomator dump) to fixed coordinates, which drift because the viewer restores its scroll position. Each link on the page appears there as "Link: …".
  • Checking what was copied. Paste it into a text field, such as Settings' search, and read the field back from the dump.
  • The system text toolbar is not in the dump; take a screenshot to find it.
  • After a reboot the emulator's downloads may be empty; push the fixtures again.