2017-07-14 124 views
0

我面對一些問題的警告在以下情況:單元測試錯誤扔

let expect = expectation(description: "Async network call") 
SomeManager.executeCall { result in 
    do { 
     /// 1. 
     XCTAssertThrowsError(try CoreManager.method()) 
     expect.fulfill() 
    } catch {} 
} 

waitForExpectations(timeout: 15.0, handler: nil) 

在1編譯器提供了一個錯誤,在不可達

catch塊,因爲沒有拋出的錯誤會在不阻止

,如果我刪除DO-趕上給出一個錯誤,即:

從拋功能型到非投擲函數類型的轉換無效......

回答

0

XCTAssertThrowsError調用燕子的錯誤,所以你不應該需要一個do /漁獲物。 對我來說看起來像一個錯誤。 作爲一種變通方法嘗試包裹檢查功能,這樣

func mustThrow() { 
    XCTAssertThrowsError(try CoreManager.method()) 
} 

,然後調用

SomeManager.executeCall { result in 
    /// 1. 
    mustThrow() 
    expect.fulfill() 
} 

你可以在本地測試定義功能,避免在文件中污染的名稱。