Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Oct 1, 2019. It is now read-only.

Create unit tests for methods that use NSAssert as pre-condition check.

License

NotificationsYou must be signed in to change notification settings

lovoo/LVForgivingAssert

Repository files navigation

CI StatusCarthage compatibleCocoaPods CompatibleCocoaPods

What does it do?

Sometimes it is necessary to have parameters in a method that are not nil. Especially for Swift compatibility there are often _Nonnull arguments added, but it is not possible to prohibit Objective-C callers to call a method with nil. Xcode will warn you when using the nil literal but not, when using a nil named pointer like the following example:

- (NSString *)aMethodWithNonnullArgument:(NSString *_Nonnull)string;
NSString *string;[selfaMethodWithNonnullArgument:string];

The usual approach is to use NSAssert to crash a development version when this occurs. This helps very much during development process and forces the caller to call the method correctly. But most times, it’s not that easy and there needs to be a fallback in production mode when NSAssert does not work.When unit testing this method, the app is in debug mode in the most configurations, so you can only test if the method throws:

NSString *string;XCTAssertThrows([selfaMethodWithNonnullArgument:string]);

With LVForgivingAssert it’s also possible to test the method without having NSAssert enabled while testing in debug mode:

LVIgnoreAssert(^{XCTAssertNil([selfaMethodWithNonnullArgument:string]);});

How does it work?

This very tiny library adds a NSAssertionHandler subclass that is set temporarily as the current assertion handler. It does not enable NSAssert and ignores it instead. After the macromis blocked, the original NSAssertionHandler is set, so it does not effect your app behaviour.See the example for more information.

Example

To run the example project, clone the repo, and runpod install from the Example directory first. The pod is used in the test target, so be sure to hit cmd+U in Xcode or select the 'Test' menu item.

Requirements

Installation

LVForgivingAssert is available throughCocoaPods. To installit, simply add the following line to your Podfile:

pod"LVForgivingAssert"

Author

Benjamin Herzog,mail@benchr.de

License

See the LICENSE file for more info.

About

Create unit tests for methods that use NSAssert as pre-condition check.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp