LoginSignup
0
0

More than 5 years have passed since last update.

Espressoで複数のRuleを指定する

Last updated at Posted at 2019-03-06

これは何?

Espressoを使ってUIテストを行う時にデバイス利用のPermissionを自動で許可する方法はいくつかあるけど、Rulesが複数個になってしまう、、、というのを解決します。
言語はKotlinです。

では、サクッと

例えば、StartのActivityをHogeActivityと指定しているけど、GPSのPermissionも自動で許可させたい場合を想定するとはこう書きます。

MyHogeActivityTest.kt
@Rule @JvmField
var mActivityTestRule = ActivityTestRule(HogeActivity::class.java)

@Rule @JvmField
var mGrantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION)

importとかはこれが必須になります。
kotlin:MyHogeActivityTest.kt
import android.support.test.rule.ActivityTestRule
import android.support.test.rule.GrantPermissionRule

app/build.gradle
...
dependencies {
...
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'junit:junit:4.12'
...
}

以上!

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