Swift Unit Testing and AVFoundation: how to test for the presence/absence of a valid capture device?

Viewed 1161

I'm coding an app that uses the camera(s) of the device, and I'm trying my hand at TDD seriously for the first time.

I am trying to test this function, specifically:

func startRunning(cameraPosition: CameraPosition) -> CaptureSessionPreview?

where CameraPosition is an enum (front and back cases) and CaptureSessionPreview is a protocol that defines an object/struct that has a video layer (like AVCaptureVideoPreviewLayer) to display.

I'd like to write tests to define what will happen when there is or isn't a specific camera (front or rear) available.

I'm using a mock AVCaptureDevice that i can init with a position and injecting it to test for the presence or absence of a device, but I also want to test that I can indeed init an AVCaptureSession with the camera as input (otherwise I should still get an error).

I'm struggling trying to init AVCaptureDeviceInput with a valid mock (it always returns nil for me). Is this even the best way to test it? Help?

0 Answers
Related