This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class MockWebServerBaseTest { | |
private lateinit var mockServer: MockWebServer | |
@Before | |
open fun setUp() { | |
this.configureMockServer() | |
} | |
@After |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalCoroutinesApi | |
@RunWith(MockitoJUnitRunner::class) | |
class PhotosViewModelTest { | |
@get:Rule | |
val testInstantTaskExecutorRule: TestRule = InstantTaskExecutorRule() | |
@get:Rule | |
val testCoroutineRule = TestCoroutineRule() | |
private lateinit var viewModel: PhotosViewModel | |
@Mock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalCoroutinesApi | |
class TestCoroutineRule : TestRule { | |
private val testCoroutineDispatcher = TestCoroutineDispatcher() | |
private val testCoroutineScope = TestCoroutineScope(testCoroutineDispatcher) | |
override fun apply(base: Statement?, description: Description?) = object : Statement() { | |
@Throws(Throwable::class) | |
override fun evaluate() { | |
Dispatchers.setMain(testCoroutineDispatcher) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mockitoCoreVersion = "3.3.3" | |
testImplementation "org.mockito:mockito-core:$mockitoCoreVersion" | |
def archCoreTest = "2.1.0" | |
testImplementation "androidx.arch.core:core-testing:$archCoreTest" | |
def coroutinesTest = "1.3.4" | |
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesTest" | |
def mockWebserverVersion = "4.7.2" | |
testImplementation "com.squareup.okhttp3:mockwebserver:$mockWebserverVersion" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//HomeFragment logic and methods | |
//Calls increment before the query to API | |
private fun initViewModels() { | |
if (null == photosViewModel) { | |
//creates viewModel | |
//..... | |
EspressoIdlingResource.increment() | |
photosViewModel?.loadData() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package co.cdmunoz.nasaroverphotos.utils.test | |
import androidx.test.espresso.idling.CountingIdlingResource | |
object EspressoIdlingResource { | |
private const val RESOURCE = "GLOBAL" | |
@JvmField | |
val countingIdlingResource = CountingIdlingResource(RESOURCE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@LargeTest | |
@RunWith(AndroidJUnit4::class) | |
class HomeFragmentUITest { | |
@get:Rule | |
val activityTestRule = ActivityScenarioRule(MainActivity::class.java) | |
@Before | |
fun setUp() { | |
IdlingRegistry.getInstance().register(EspressoIdlingResource.countingIdlingResource) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4::class) | |
class OnBoardingActivityUITest { | |
@get:Rule | |
val activityScenarioRule = activityScenarioRule<OnBoardingActivity>() | |
@Test | |
fun initial_state_on_boarding_screen_UI_test() { | |
val titleToCheck = "On Boarding Title 1" | |
onView(withText(titleToCheck)).check(matches(isDisplayed())) | |
onView(withId(R.id.on_board_bottom_msg)).check(matches(isDisplayed())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def junitExtVersion = "1.1.1" | |
androidTestImplementation "androidx.test.ext:junit:$junitExtVersion" | |
androidTestImplementation "androidx.test.ext:junit-ktx:$junitExtVersion" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OnBoardingActivity : AppCompatActivity() { | |
private var onBoardingPageChangeCallback = object : ViewPager2.OnPageChangeCallback() { | |
override fun onPageSelected(position: Int) { | |
updateCircleMarker(binding, position) | |
} | |
} | |
private lateinit var binding: ActivityOnBoardingBinding | |
override fun onCreate(savedInstanceState: Bundle?) { |