然后在TestDemoTests文件夹下创建UrlTests文件,此时由于该类只需要在测试中才能用到,所以只需要在Targets选择TestDemoTests可以了:

  创建完成后,导入XCTest框架,并使该类继承自XCTestCase,然后录入测试代码:
import XCTest
class UrlTests: XCTestCase {
var urlInstance = Url(baseUrl: "http://localhost:8080/api/")
func testShouldGetCorrectPathWhenNoSegmentProvided() {
let resourcePath = "customers"
let result = urlInstance.getActualPathFrom(resourcePath, segments: [String:String]())
XCTAssertEqual(result, "http://localhost:8080/api/customers", "Can not get corrent path when no segments provided")
}
func testGetCorrectPathGivenOneSegment() {
let resourcePath = "customer/{id}"
let result = urlInstance.getActualPathFrom(resourcePath, segments: ["id": "10"]);
XCTAssertEqual(result, "http://localhost:8080/api/customer/10", "Can not get corrent path when only one segment provided")
}
}
  后Command+U执行测试