Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between XCTAssert and assert in Swift

What's the difference between XCTAssert() and assert() in Swift?

like image 546
Daniel Gomez Rico Avatar asked Dec 12 '14 20:12

Daniel Gomez Rico


1 Answers

XCTAssert is one of a family of asserts for unit testing from the XCTest framework, and should only be present in Unit Test Targets (i.e. not in your application code). If the assert fails, it does not terminate the execution of the test harness or hosting application, but records and reports the failure.

Unit test assertions are recorded and reported during the "Test" action (compare to "Run" and "Install" actions).

assert is a debug-build-only swift assert for user code. This can be present in your application or framework target bundles. If the assert fails, the current application is stopped in a debuggable state, or terminated if not under the debugger. Equivalent to Objective-C's NSAssert. In release builds, the assert is ignored.

like image 109
Alex Brown Avatar answered Sep 24 '22 23:09

Alex Brown