This test plan focuses on preventing regressions from the planned Core ML/Vision pipeline changes (request reuse, error handling, orientation handling, async model loading, and pixel format tuning). It covers new unit and integration tests plus manual checks where automation is difficult.
- Add a
CoreMLPlayerTeststarget with XCTest. - Fixtures: small sample video (landscape) and portrait stills for orientation checks; synthetic pixel buffers in
kCVPixelFormatType_32BGRAand model-preferred formats; a lightweight mockMLModelandVNCoreMLModelwrapper for failure injection. - Environment: ensure tests run on device and simulator; gate GPU-dependent tests with
XCTSkipwhenMTLDeviceis unavailable.
- Async load success:
MLModel.load(contentsOf:configuration:)resolves and returns a non-nil model; configuration respectscomputeUnitsandallowLowPrecisionAccumulationOnGPU. - Compilation fallback: when passed an uncompiled model URL, verify the code compiles once and caches the compiled URL; subsequent loads reuse the compiled path.
- Error surfacing: inject an invalid model and assert the load path propagates errors (no silent failures).
- Warm-up inference: after loading, assert a single warm-up request executes without throwing and marks the model as ready for reuse. YOLOv3Tiny emits a benign console warning about missing
precisionRecallCurvesbecause it is not an updatable model; the test should tolerate this log as long as the request succeeds.
- Request reuse: repeated video frames should reuse the same
VNCoreMLRequest/VNSequenceRequestHandler; track allocations or identifiers to ensure no per-frame recreation. - Error handling: simulate a Vision error (e.g., mismatched pixel buffer attributes) and assert errors are logged/propagated, not swallowed.
- Crop/scale compliance: validate
imageCropAndScaleOptionmatches the model’s expected input; tests check.centerCrop(or configured option) is applied rather than a hard-coded default.
- Orientation mapping: feed landscape and portrait CMSampleBuffers and assert the resolved
CGImagePropertyOrientationpassed to Vision matches the video track orientation. - Pixel format selection: when
idealFormatis available,AVPlayerItemVideoOutputshould be initialized with matching pixel buffer attributes; tests confirm the requested attributes and that fallback to BGRA occurs when unsupported. - Pixel buffer validity: confirm the request handler rejects nil or stale pixel buffers and surfaces an error.
- Deterministic outputs: run inference on a fixed fixture image and assert detections (labels/bounding boxes) stay within a tolerance envelope to catch pre/post-processing regressions.
- Performance budget: use
measureblocks to ensure per-frame inference time stays within the real-time threshold (e.g., <33ms on a supported device) after changes. - Max-FPS loop stability: stress test with rapid frame delivery to ensure no memory growth (via allocations audit) and no dropped frames due to request recreation.
- Playback overlay: snapshot tests for the detection overlay view to ensure bounding boxes render in correct orientation and aspect after crop/scale changes.
- Lifecycle: start/stop playback multiple times to verify requests/handlers are released and recreated cleanly; assert no crashes when the app re-enters foreground.
- Error messaging: inject model load failures and Vision errors and assert user-facing alerts or logs appear (and do not block main thread responsiveness).
- On-device smoke test: run the app on a physical device, confirm stable FPS, correct bounding boxes, and no UI hangs when toggling models or playback speed.
- GPU/CPU toggle: switch compute units (CPU-only vs. ANE/GPU) to observe consistency and ensure the app handles hardware differences gracefully.
- Integrate tests into CI with separate schemes for unit/integration and UI snapshot runs.
- Capture performance baselines in CI artifacts for regression tracking.
- Provide toggles/env vars to skip GPU-reliant tests on unsupported runners.