sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Remove force unwraps from test code

Open armcknight opened this issue 1 year ago • 2 comments

Description

We have numerous force-unwraps in our Swift test code, which make it harder to iterate locally if you make a breaking change. This causes the test process to crash if an assumption is broken, disallowing the complete suite of tests to run, preventing you from seeing the total list of tests that would fail. This could mean many cycles of fixing one breakage, run the suite again, encounter the next crash. Of course, it's more painful if it happens in CI (and is harder to see what's going on there, too).

Convert such force unwraps to either guard...else { XCTFail("message"); return } or try XCTUnwrap(...)

armcknight avatar Jan 27 '24 02:01 armcknight

@armcknight, to enforce this rule, we could enable the swiftlint rule for the tests again https://github.com/getsentry/sentry-cocoa/blob/faaf832acdece0118cf8e9e20d3e4cf3c568691f/Tests/.swiftlint.yml#L6 We could allow specific usages of it in the code by disabling the lining rule only locally with code comments.

philipphofmann avatar Jan 29 '24 14:01 philipphofmann

@philipphofmann excellent idea, I'm all for it 👍🏻

armcknight avatar Jan 29 '24 23:01 armcknight