Skip to content

Instantly share code, notes, and snippets.

@75py
Created October 10, 2015 05:29
Show Gist options
  • Save 75py/a0feeba5d264c9f3be9e to your computer and use it in GitHub Desktop.
Save 75py/a0feeba5d264c9f3be9e to your computer and use it in GitHub Desktop.
Kotlinのテストで@rule
dependencies {
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:23.0.1'
androidTestCompile 'com.android.support.test:runner:0.4'
androidTestCompile 'com.android.support.test:rules:0.4'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
androidTestCompile 'com.squareup.assertj:assertj-android:1.1.0'
}
package com.nagopy.android.aplin
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import android.widget.TextView
import org.assertj.android.api.Assertions
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class MainActivityTest {
/*
@Rule
public val rule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
って書くと
The @Rule 'rule' must be public.
って怒られる
*/
val rule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
@Rule
public fun getActivityTestRule() = rule
@Test
public fun test() {
val textView = rule.activity.findViewById(R.id.text) as TextView
Assertions.assertThat(textView).isVisible()
Assertions.assertThat(textView).hasText(R.string.app_name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment