LoginSignup
1
0

More than 1 year has passed since last update.

Quick v5からv6へのバージョンアップ時の対応

Posted at

Quickをv5からv6にバージョンアップをした際にやった対応内容をかんたんにまとめました。

Quick v6のリリースノートはこちらです。
https://github.com/Quick/Quick/releases/tag/v6.0.0

v6で何が変わったかというと一番の大きな変更はこちらのAsync/awaitサポートです。

Async/await support. All tests now run in an async context.

テストでasync/awaitが使えるようになったというメリットがあるのですが、
単純にアップデートしたい場合はすべてのテストがasync contextで実行されるように変更されている(いままではmainだった)ので場合によっては結構な影響があります

Again, with the async support, all tests now run in an async context. This will require you to make changes, especially if you use Nimble.

対応した内容

waitUntil

NimbleのwaitUntilをつかっていたので、こちらをawait waitUntilに変更しました。

エラー

Global function 'waitUntil' is unavailable from asynchronous contexts; the sync version of `waitUntil` does not work in async contexts. Use the async version with the same name as a drop-in replacement; this is an error in Swift 6

toEventually

NimbleのtoEventuallyをつかっていたので、 expect(Hoge).toEventually(… の先頭にasyncを追加しました。

エラー

Instance method 'toEventually' is unavailable from asynchronous contexts; the sync version of `toEventually` does not work in async contexts. Use the async version with the same name as a drop-in replacement; this is an error in Swift 6

main threadに変更

テストがmain threadで実行されなくなったので、例えばViewModelのdriverのテストなどをしている場合には動かなくなってしまいます。

対応方法としてはclosureをmain threadで走るように指定します。

it("runs on the main thread") { @MainActor in
    // contents of this closure will run in the main actor.
}

または全てmain threadで動かしたい場合はクラス自体をMainActorにすればよさそうでした。

@MainActor
class MySpec: QuickSpec {

ただ全部main threadで実行してしまうと並行でテストを実行できなくなってしまうのでなるべく避けたいですね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0