0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

kotlinのUnitTestはrunTestを使うといいかも

Posted at

runBlockingはrunTestに置き換えてもいいかも

  • runTestは内部で、delayなどの明らかに処理が止まる処理を、自動でスキップしてくれるなどの処理が備わっている
    そのため、テストの実行時間が短くなるなどのメリットがある
    (例えばrunBlockingだと、テスト対象メソッドにdelayで10秒待つ処理がると、きっちり10秒待ってからじゃないと、次の処理に進めない。しかし、runTestは、delayで10秒待つ処理があった場合、10秒待ったことにして、次の処理を進めてくれるため、テストにかかる時間が短くなる)

参考サイト

On JVM and Native, this function behaves similarly to runBlocking, with the difference that the code that it runs will skip delays. This allows to use delay in tests without causing them to take more time than necessary. On JS, this function creates a Promise that executes the test body with the delay-skipping behavior.

JVM およびネイティブでは、この関数は と同様に動作しますが、実行するコードが遅延をスキップするという違いがあります。これにより、テストに必要以上の時間をかけずに、テストで遅延runBlockingを使用できます。JS では、この関数は、遅延スキップ動作でテスト本体を実行する を作成します。Promise

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?