UPDATE:
It seems that this functionality should be supported in future versions of Swift 2.0 / XCode 7, which are likely to include try / catch support, so this question is likely to be controversial. I will try to update this post accordingly when they are not in beta.
ORIGINAL QUESTION:
In Swift, although I assume that the question / answer will be applicable to Objective-C, I want to write the foo function in the format:
public class SomeClass{ public func foo(someString:String){
I use the assert call because I believe that this is what Apple recommends, rather than throwing exceptions, as is customary in other languages.
However, in my unit test, I want to make sure that the function does not really work when the someString parameter is an empty string:
class SomeClass_Tests:XCTestCase{ func test_foo_someStringParamaterIsEmpty_error(){
I cannot find documentation or messages about this situation, although I believe that this is a very important unit test to ensure proper behavior and use of classes and libraries.
In other languages, which include exception / exception handling, assert will be replaced with something like throw SomeError() , and then in unit test you can simply transfer the action to a try / catch and claim that the exception is really set like this:
class SomeClass_Tests:XCTestCase{ func test_foo_someStringParamaterIsEmpty_error(){
But there are no such designs or equivalent jobs in Swift that I saw in the documentation. Are there any known solutions or workarounds for performing such tests?
ios unit-testing assertions swift xctest
Zachary smith
source share