Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API がランダムで失敗するため、テストが曖昧になっている。 #79

Open
es-kumagai opened this issue May 2, 2024 · 1 comment

Comments

@es-kumagai
Copy link
Collaborator

現在は API がときどき失敗するタイミングを外から制御できないため、テストのフローがランダムで変化する可能性がある。

それを想定したテストになっているものの、そのテストケースは次の2通りが、状況によって検査される(実行のたびに状況が変わり、そのときに片方は検査されない)

  • API がエラーにならなかったときは、レスポンスを検査する。
  • API がエラーになったときは、ランダムで発生したエラーであれば成功とする。

以下は、この件が該当するテストコードの1つ。

        do {
            let responseJSON = try YumemiWeather.fetchWeatherList(parameter)
            let dateFormatter = DateFormatter()
            dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
            let decoder = JSONDecoder()
            decoder.keyDecodingStrategy = .convertFromSnakeCase
            decoder.dateDecodingStrategy = .formatted(dateFormatter)
            let response = try decoder.decode([AreaResponse].self, from: Data(responseJSON.utf8))
            XCTAssertEqual(response.count, Area.allCases.count)
        }
        catch let error as YumemiWeatherError {
            XCTAssertEqual(error, YumemiWeatherError.unknownError)
        }
        catch {
            XCTFail()
        }
@es-kumagai
Copy link
Collaborator Author

#81 は、当件を解消する PR です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant