mardi 16 février 2021

How to write tests using fake current date

I am trying to write some epsresso tests to just confirm that my date textview displays the correct date. I am new to espresso testing but I believe it is good practice.

So I have a fake dateProvider

interface DateProvder{
fun getCurrentDate(): Date

}

In the fragment where I am writing tests I have it like this

@Inject
latentint var date: DateProvider

@Test
 fun allDatesDisplayasExpected() {
     onView(withId(R.id.data)).check(
         matches(
             withViewAtPosition(
                 0, hasDescendant(
                     allOf(
                         withId(R.id.date)
                     )
                 )
             )
         )
     )
 }

I bet my question is how can I test for this time format 10:19 am , Thursday , and 02/12/2021 three formats.

Aucun commentaire:

Enregistrer un commentaire