File tree Expand file tree Collapse file tree 7 files changed +12
-10
lines changed
src/androidTest/java/com/google/samples/apps/sunflower Expand file tree Collapse file tree 7 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ dependencies {
7373 androidTestImplementation " androidx.test.espresso:espresso-contrib:$rootProject . espressoVersion "
7474 androidTestImplementation " androidx.test.espresso:espresso-core:$rootProject . espressoVersion "
7575 androidTestImplementation " androidx.test.espresso:espresso-intents:$rootProject . espressoVersion "
76+ androidTestImplementation " androidx.test.ext:junit:$rootProject . testExtJunit "
7677 androidTestImplementation " androidx.test.uiautomator:uiautomator:$rootProject . uiAutomatorVersion "
7778 androidTestImplementation " androidx.work:work-testing:$rootProject . workVersion "
7879 androidTestImplementation " com.google.truth:truth:$rootProject . truth "
Original file line number Diff line number Diff line change 1717package com.google.samples.apps.sunflower
1818
1919import android.view.Gravity
20- import androidx.test.InstrumentationRegistry
2120import androidx.test.espresso.Espresso.onView
2221import androidx.test.espresso.action.ViewActions
2322import androidx.test.espresso.action.ViewActions.click
@@ -29,6 +28,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
2928import androidx.test.espresso.matcher.ViewMatchers.isRoot
3029import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
3130import androidx.test.espresso.matcher.ViewMatchers.withId
31+ import androidx.test.platform.app.InstrumentationRegistry
3232import androidx.test.rule.ActivityTestRule
3333import androidx.test.uiautomator.UiDevice
3434import com.google.samples.apps.sunflower.utilities.getToolbarNavigationContentDescription
Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ import android.accessibilityservice.AccessibilityService
2020import android.content.Intent
2121import android.os.Bundle
2222import androidx.navigation.findNavController
23- import androidx.test.InstrumentationRegistry
23+ import androidx.test.ext.junit.runners.AndroidJUnit4
24+ import androidx.test.platform.app.InstrumentationRegistry
2425import androidx.test.espresso.Espresso.onView
2526import androidx.test.espresso.action.ViewActions.click
2627import androidx.test.espresso.intent.Intents
@@ -30,7 +31,6 @@ import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra
3031import androidx.test.espresso.intent.matcher.IntentMatchers.hasType
3132import androidx.test.espresso.matcher.ViewMatchers.withId
3233import androidx.test.rule.ActivityTestRule
33- import androidx.test.runner.AndroidJUnit4
3434import com.google.samples.apps.sunflower.utilities.chooser
3535import com.google.samples.apps.sunflower.utilities.testPlant
3636import org.hamcrest.CoreMatchers.allOf
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ package com.google.samples.apps.sunflower.data
1818
1919import androidx.arch.core.executor.testing.InstantTaskExecutorRule
2020import androidx.room.Room
21- import androidx.test.InstrumentationRegistry
2221import androidx.test.espresso.matcher.ViewMatchers.assertThat
22+ import androidx.test.platform.app.InstrumentationRegistry
2323import com.google.samples.apps.sunflower.utilities.getValue
2424import com.google.samples.apps.sunflower.utilities.testCalendar
2525import com.google.samples.apps.sunflower.utilities.testGardenPlanting
@@ -41,7 +41,7 @@ class GardenPlantingDaoTest {
4141 var instantTaskExecutorRule = InstantTaskExecutorRule ()
4242
4343 @Before fun createDb () {
44- val context = InstrumentationRegistry .getTargetContext()
44+ val context = InstrumentationRegistry .getInstrumentation().targetContext
4545 database = Room .inMemoryDatabaseBuilder(context, AppDatabase ::class .java).build()
4646 gardenPlantingDao = database.gardenPlantingDao()
4747
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ package com.google.samples.apps.sunflower.data
1818
1919import androidx.arch.core.executor.testing.InstantTaskExecutorRule
2020import androidx.room.Room
21- import androidx.test.InstrumentationRegistry
22- import androidx.test.runner.AndroidJUnit4
21+ import androidx.test.ext.junit.runners.AndroidJUnit4
22+ import androidx.test.platform.app.InstrumentationRegistry
2323import com.google.samples.apps.sunflower.utilities.getValue
2424import org.hamcrest.Matchers.equalTo
2525import org.junit.After
@@ -41,7 +41,7 @@ class PlantDaoTest {
4141 var instantTaskExecutorRule = InstantTaskExecutorRule ()
4242
4343 @Before fun createDb () {
44- val context = InstrumentationRegistry .getTargetContext()
44+ val context = InstrumentationRegistry .getInstrumentation().targetContext
4545 database = Room .inMemoryDatabaseBuilder(context, AppDatabase ::class .java).build()
4646 plantDao = database.plantDao()
4747
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ package com.google.samples.apps.sunflower.viewmodels
1818
1919import androidx.arch.core.executor.testing.InstantTaskExecutorRule
2020import androidx.room.Room
21- import androidx.test.InstrumentationRegistry
21+ import androidx.test.platform.app. InstrumentationRegistry
2222import com.google.samples.apps.sunflower.data.AppDatabase
2323import com.google.samples.apps.sunflower.data.GardenPlantingRepository
2424import com.google.samples.apps.sunflower.data.PlantRepository
@@ -40,7 +40,7 @@ class PlantDetailViewModelTest {
4040
4141 @Before
4242 fun setUp () {
43- val context = InstrumentationRegistry .getTargetContext()
43+ val context = InstrumentationRegistry .getInstrumentation().targetContext
4444 appDatabase = Room .inMemoryDatabaseBuilder(context, AppDatabase ::class .java).build()
4545
4646 val plantRepo = PlantRepository .getInstance(appDatabase.plantDao())
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ buildscript {
4343 runnerVersion = ' 1.0.1'
4444 supportLibraryVersion = ' 1.1.0-alpha05'
4545 truth = ' 0.42'
46+ testExtJunit = ' 1.1.0'
4647 uiAutomatorVersion = ' 2.2.0'
4748 workVersion = ' 2.1.0-alpha02'
4849 }
You can’t perform that action at this time.
0 commit comments