0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MVVM+CoroutineFlowのUnitテストを書く(準備編)

Posted at

はじめに

ついにUnitテストと真面目に向き合う時がやってきたので、採択技術や書き方をメモしておく。

採択したもの

  • JUnit4
  • Mockk
  • Truth(Googleが出しているアサーションライブラリ)

↓kts化してない人は読み替えてください

build.gradle.kts(app)
    // test
    testImplementation("junit:junit:4.13.2")
    testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.8.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    testImplementation("io.mockk:mockk:1.12.5")
    testImplementation("com.google.truth:truth:1.1.3")
    testImplementation("androidx.arch.core:core-testing:2.1.0")
    testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1")

なぜそうしたのか

  • Mockk : Coroutineをサポートしているライブラリだから。
    • coEvery{} と書くとCoroutineによる処理の実行がモックできる。
  • Truth : 値の比較をするための鉄板ライブラリ。
  • JUnit4 : 一旦慣れているものを使う方向で。追々JUnit5に移行したい。

参考にした本、サイト

Android ユニットテスト ヒッチハイク・ガイド | 糖衣構文
https://syntaxsugar.booth.pm/items/4186246

【Android/Kotlin】JUnit4 によるユニットテストを試してみた
https://zenn.dev/kotaro666/articles/android-unit-test-sample

ahmedeltaher/MVVM-Kotlin-Android-Architecture
https://github.com/ahmedeltaher/MVVM-Kotlin-Android-Architecture

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?