【发布时间】:2016-03-20 14:02:55
【问题描述】:
我正在尝试编写一个方法,其中数据对象(领域)使用 Alamofire 刷新其属性。但我不知道如何对其进行单元测试。
import Alamofire
import RealmSwift
import SwiftyJSON
class Thingy: Object {
// some properties
dynamic var property
// refresh instance
func refreshThingy() {
Alamofire.request(.GET, URL)
.responseJSON {
response in
self.property = response["JSON"].string
}
}
}
在我的单元测试中,我想测试Thingy 是否可以正确地从服务器刷新。
import Alamofire
import SwiftyJSON
import XCTest
@testable import MyModule
class Thingy_Tests: XCTestCase {
func testRefreshThingy() {
let testThingy: Thingy = Thingy.init()
testThingy.refreshProject()
XCTAssertEqual(testThingy.property, expected property)
}
如何为此正确设置单元测试?
【问题讨论】:
标签: swift unit-testing alamofire