Accessing resources in an android test project

后端 未结 4 1168
天涯浪人
天涯浪人 2020-12-06 10:06

I have setup an android test project that runs junit tests. It\'s using two eclipse projects \"Application\" and \"ApplicationTest\" where my tests are in the \"ApplicationT

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 10:06

    With build tools 3.0.0 you can use ActivityTestRule

    @RunWith(AndroidJUnit4::class)
    @SmallTest
    class MainActivityTest {
        @Rule
        @JvmField
        var mainActivityRule = ActivityTestRule(MainActivity::class.java)
    
        private val baseUrl: String
            get() {
                return mainActivityRule.activity.getString(R.string.base_url)
            }
    
        @Test
        fun launchingWithMovieIntent() {
                assert.that(baseUrl, equalTo("someValue")
            }
        }
    }
    

提交回复
热议问题