从URL单元测试UIImage

时间:2018-04-24 17:48:20

标签: swift unit-testing uiimage

我正在尝试测试一个从网址创建图片的功能。我的单元测试看起来像这样:

func testImageFromURL() {

    //when testing callbacks use a testExpectation
    let testExpectation = expectation(description: "Format function timed out")

    //1.Given
    let dictPhotoData = ["isfriend":false, "farm": 1, "id":"40946679254", "server":"875", "secret":"c6e491e979", "owner":"138560875@N08", "title":"Is it spring yet? Eastern garter snake (Thamnophis sirtalis)", "ispublic":true, "isfamily":false] as [String : Any]

    //2.When
    let thisPhotoObj = FF_PhotoObject(dictPhotoData)
    if let thisPhotoURL = thisPhotoObj?.photoUrl as? URL {

        myAPIManager.getImageFromData(thisPhotoURL, completion: { (_ thisImage:UIImage) in

            //3. Then
            //-->Not sure what to test for here.
            testExpectation.fulfill()

        })
    }

    waitForExpectations(timeout: 7) { error in
        if let error = error {
            XCTFail("waitForExpectationsWithTimeout errored: \(error)")
        }
    }
}

我只是不确定要测试UIImage的内容。

0 个答案:

没有答案