LoginSignup
1
0

More than 5 years have passed since last update.

android studio unit tests

Posted at

android studio unit tests

パソコン整理してたら、こんなこと書いてたので公開

android studioでunit testsできる環境を構築する

公式ページ通りにやります

app/build.gradle

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.+'

ディレクトリ

AndroidStudioProjects/au_wallet/app/src/test

mkdir test する

例えばこうなる

~/AndroidStudioProjects/au_wallet/app/src/test
└── java
    └── jp
        └── auone
            └── wallet
                └── util
                    └── NetworkUtilTest.java

ローカルでテストを動かす

Build Variants

bv

クリックして表示します

Test Artifact

Imgur

Unit Testsを選択します

テスト実行用の設定を追加します

Imgur

Edit configurations > +ボタンで設定を増やす

JUnitを選ぶ

名前はSmallTestにしてます。

Configuration
  • Test Kind : all in package
  • Package : jp.auone.wallet
  • Search for tests : In whole project

これで、設定を作成して、SmallTestを選択してる状態で再生ボタン押せば、テストがローカルで実行できます。

参考

http://blog.recruit-tech.co.jp/2015/08/10/android-allstars-201508/
https://github.com/hotchemi/awesome-android-testing
https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support
http://mockito.org/
http://qiita.com/asuuma/items/80169afefbe9718a9205

なぜSmallTestって名前か

@SmallTest
純粋なビジネスロジックをテストする。対象はUtilやHelper、Model及びデータ取得の為のリポジトリ層
ライブラリ: Robolectric3, JUnit4, Mockito, AssertJ
@MediumTest
UIロジックやユーザーのアクション及びそれに伴って変化するViewの状態をテストする。対象はCustom ViewやActivity/FragmentもしくはPresenter
ライブラリ: Espresso2, AndroidTestCase, Mockito, Spoon, assertj-android
@LargeTest
「あるシナリオが実行できるか」という観点でテストする。何をアサートするかは一律に定義できないので画面のスクリーンショットを撮って人間が確認する方が無難。リグレッションテストも兼ねる。
ライブラリ: Appium, calabash-android, UI automator
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