I'm trying to write a method where a data object (Realm) refreshes it's properties using Alamofire. But I can't figure out how to unit test it.
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
}
}
}
In my unit tests, I want to test that the Thingy
can refresh from server properly.
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)
}
How do I properly set up unit tests for this?
See Question&Answers more detail:os