// // yanaAPITests.swift // yanaAPITests // // Created by P on 2025/5/27. // import XCTest @testable import yana final class yanaAPITests: XCTestCase { override func setUpWithError() throws { // Put setup code here. This method is called before the invocation of each test method in the class. } override func tearDownWithError() throws { // Put teardown code here. This method is called after the invocation of each test method in the class. } func testExample() throws { // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct results. // Any test you write for XCTest can be annotated as throws and async. // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. } func testPerformanceExample() throws { // This is an example of a performance test case. measure { // Put the code you want to measure the time of here. } } func testClientInit_Success() { let expectation = self.expectation(description: "clientInit success") API.clientInit { result in switch result { case .success(let data): XCTAssertNotNil(data) // 可根据实际返回内容进一步断言 case .failure(let error): XCTFail("Expected success, got error: \(error)") } expectation.fulfill() } waitForExpectations(timeout: 5, handler: nil) } func testClientInit_Failure() { // 可通过mock或断网等方式测试失败场景 // 这里只做结构示例 let expectation = self.expectation(description: "clientInit failure") // 假设API支持注入baseURL或mock API.clientInit { result in switch result { case .success(_): // 若期望失败则此处应fail XCTFail("Expected failure, got success") case .failure(let error): XCTAssertNotNil(error) } expectation.fulfill() } waitForExpectations(timeout: 5, handler: nil) } }